diff --git a/lib/util_mustache.js b/lib/util_mustache.js index b88f3da..26b05e7 100644 --- a/lib/util_mustache.js +++ b/lib/util_mustache.js @@ -12,8 +12,25 @@ // the term "alphanumeric" includes underscores. -// todo: document this exact regex long form. -var partialsRE = new RegExp(/{{>\s*?([\w\-\.\/~]+)(?:\:[A-Za-z0-9-_|]+)?(?:(?:| )\(.*)?(?:\s*)?}}/g); +// look for an opening mustache include tag, followed by >=0 whitespaces +var partialsStr = '{{>\\s*'; + +// one or more characters comprising any combination of alphanumerics, +// hyphens, periods, slashses, and tildes +partialsStr += '([\\w\\-\\.\\/~]+)'; + +// an optional group comprising a colon followed by one or more characters +// comprising any combination of alphanumerics, hyphens, and pipes +partialsStr += '(\\:[\\w\\-\\|]+)?'; + +// an optional group of characters starting with >=0 whitespaces, followed by an +// opening parenthesis, followed by a lazy match of non-whitespace or whitespace +// characters (to include newlines), followed by a closing parenthesis +partialsStr += '(\\s*\\([\\S\\s]*?\\))?'; + +// look for >=0 whitespaces, followed by closing mustache tag +partialsStr += '\\s*}}'; +var partialsRE = new RegExp(partialsStr, 'g'); // look for an opening mustache include tag, followed by >=0 whitespaces var partialsWithStyleModifiersStr = '{{>\\s*'; @@ -29,10 +46,10 @@ partialsWithStyleModifiersStr += '(?!\\()'; // of alphanumerics, hyphens, and pipes partialsWithStyleModifiersStr += '(\\:[\\w\\-\\|]+)'; -// an optional group of characters starting with >=0 whitespaces, followed by -// an opening parenthesis, followed by any number of characters that are not -// closing parentheses, followed by a closing parenthesis -partialsWithStyleModifiersStr += '(\\s*\\([^\\)]*\\))?'; +// an optional group of characters starting with >=0 whitespaces, followed by an +// opening parenthesis, followed by a lazy match of non-whitespace or whitespace +// characters (to include newlines), followed by a closing parenthesis +partialsWithStyleModifiersStr += '(\\s*\\([\\S\\s]*?\\))?'; // look for >=0 whitespaces, followed by closing mustache tag partialsWithStyleModifiersStr += '\\s*}}'; @@ -46,14 +63,13 @@ var partialsWithPatternParametersStr = '{{>\\s*'; partialsWithPatternParametersStr += '([\\w\\-\\.\\/~]+)'; // an optional group comprising a colon followed by one or more characters -// comprising any combination of alphanumerics, -// hyphens, and pipes +// comprising any combination of alphanumerics, hyphens, and pipes partialsWithPatternParametersStr += '(\\:[\\w\\-\\|]+)?'; -// a group of characters starting with >=0 whitespaces, followed by an opening -// parenthesis, followed by any number of characters that are not closing -// parentheses, followed by a closing parenthesis -partialsWithPatternParametersStr += '(\\s*\\([^\\)]*\\))'; +// a group of characters starting with >=0 whitespaces, followed by an +// opening parenthesis, followed by a lazy match of non-whitespace or whitespace +// characters (to include newlines), followed by a closing parenthesis +partialsWithPatternParametersStr += '(\\s*\\([\\S\\s)]*?\\))'; // look for >=0 whitespaces, followed by closing mustache tag partialsWithPatternParametersStr += '\\s*}}'; @@ -72,36 +88,11 @@ listItemsStr += '(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve listItemsStr += '\\s*}}'; var listItemsRE = new RegExp(listItemsStr, 'g'); -// look for an opening mustache loop tag, followed by >=0 whitespaces -var partialKeyStr = '{{>\\s*'; - -// one or more characters comprising any combination of alphanumerics, -// hyphens, periods, slashses, and tildes -partialKeyStr += '([\\w\\-\\.\\/~]+)'; - -// an optional group of characters starting with a colon, followed by >0 -// alphanumerics, hyphens, or pipes -partialKeyStr += '(\\:[\\w\\-|]+)?'; - -// an optional group of characters starting with a colon, followed by >0 -// alphanumerics or hyphens -partialKeyStr += '(\\:[\\w\\-]+)?'; - -// an optional group of characters starting with >=0 whitespaces, followed by -// an opening parenthesis, followed by any number of characters that are not -// closing parentheses, followed by a closing parenthesis -partialKeyStr += '(\\s*\\([^\\)]*\\))?'; - -// look for >=0 whitespaces, followed by closing mustache tag -partialKeyStr += '\\s*}}'; -var partialKeyRE = new RegExp(partialKeyStr, 'g'); - var utilMustache = { partialsRE: partialsRE, partialsWithStyleModifiersRE: partialsWithStyleModifiersRE, partialsWithPatternParametersRE: partialsWithPatternParametersRE, - listItemsRE: listItemsRE, - partialKeyRE: partialKeyRE + listItemsRE: listItemsRE }; module.exports = utilMustache;