diff --git a/components/prism-handlebars.js b/components/prism-handlebars.js index e23933d467..7a7f5a41b1 100644 --- a/components/prism-handlebars.js +++ b/components/prism-handlebars.js @@ -21,8 +21,8 @@ variable: /[\s\S]+/ } }, - 'punctuation': /[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]/, - 'variable': /[^!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~\s]+/ + 'punctuation': /[!"#%&':()*+,.\/;<=>@\[\\\]^`{|}~]/, + 'variable': /[^!"#%&'()*+,\/;<=>@\[\\\]^`{|}~\s]+/ }; Prism.hooks.add('before-tokenize', function(env) { diff --git a/components/prism-handlebars.min.js b/components/prism-handlebars.min.js index 7fbab5cc83..4c8151f3ba 100644 --- a/components/prism-handlebars.min.js +++ b/components/prism-handlebars.min.js @@ -1 +1 @@ -!function(e){e.languages.handlebars={comment:/\{\{![\s\S]*?\}\}/,delimiter:{pattern:/^\{\{\{?|\}\}\}?$/i,alias:"punctuation"},string:/(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,boolean:/\b(?:true|false)\b/,block:{pattern:/^(\s*~?\s*)[#\/]\S+?(?=\s*~?\s*$|\s)/i,lookbehind:!0,alias:"keyword"},brackets:{pattern:/\[[^\]]+\]/,inside:{punctuation:/\[|\]/,variable:/[\s\S]+/}},punctuation:/[!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]/,variable:/[^!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~\s]+/},e.hooks.add("before-tokenize",function(a){e.languages["markup-templating"].buildPlaceholders(a,"handlebars",/\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/g)}),e.hooks.add("after-tokenize",function(a){e.languages["markup-templating"].tokenizePlaceholders(a,"handlebars")})}(Prism); \ No newline at end of file +!function(e){e.languages.handlebars={comment:/\{\{![\s\S]*?\}\}/,delimiter:{pattern:/^\{\{\{?|\}\}\}?$/i,alias:"punctuation"},string:/(["'])(?:\\.|(?!\1)[^\\\r\n])*\1/,number:/\b0x[\dA-Fa-f]+\b|(?:\b\d+\.?\d*|\B\.\d+)(?:[Ee][+-]?\d+)?/,boolean:/\b(?:true|false)\b/,block:{pattern:/^(\s*~?\s*)[#\/]\S+?(?=\s*~?\s*$|\s)/i,lookbehind:!0,alias:"keyword"},brackets:{pattern:/\[[^\]]+\]/,inside:{punctuation:/\[|\]/,variable:/[\s\S]+/}},punctuation:/[!"#%&':()*+,.\/;<=>@\[\\\]^`{|}~]/,variable:/[^!"#%&'()*+,\/;<=>@\[\\\]^`{|}~\s]+/},e.hooks.add("before-tokenize",function(a){e.languages["markup-templating"].buildPlaceholders(a,"handlebars",/\{\{\{[\s\S]+?\}\}\}|\{\{[\s\S]+?\}\}/g)}),e.hooks.add("after-tokenize",function(a){e.languages["markup-templating"].tokenizePlaceholders(a,"handlebars")})}(Prism); \ No newline at end of file diff --git a/tests/languages/handlebars/block_feature.test b/tests/languages/handlebars/block_feature.test index dd2c74e9c7..46182ddd43 100644 --- a/tests/languages/handlebars/block_feature.test +++ b/tests/languages/handlebars/block_feature.test @@ -1,21 +1,28 @@ {{#each comments}}{{/each}} {{~#if isActive~}}{{~/if~}} +{{#let a as |b|}}{{/let}} ---------------------------------------------------- [ - ["handlebars", [ - ["delimiter", "{{"], ["block", "#each"], ["variable", "comments"], ["delimiter", "}}"] - ]], - ["handlebars", [ - ["delimiter", "{{"], ["block", "/each"], ["delimiter", "}}"] - ]], - ["handlebars", [ - ["delimiter", "{{"], ["punctuation", "~"], ["block", "#if"], ["variable", "isActive"], ["punctuation", "~"], ["delimiter", "}}"] - ]], - ["handlebars", [ - ["delimiter", "{{"], ["punctuation", "~"], ["block", "/if"], ["punctuation", "~"], ["delimiter", "}}"] - ]] + ["handlebars",[ + ["delimiter","{{"],["block","#each"],["variable","comments"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["block","/each"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["punctuation","~"],["block","#if"],["variable","isActive"],["punctuation","~"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["punctuation","~"],["block","/if"],["punctuation","~"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["block","#let"],["variable","a"],["variable","as"],["punctuation","|"],["variable","b"],["punctuation","|"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["block","/let"],["delimiter","}}"]] + ] ] ---------------------------------------------------- diff --git a/tests/languages/handlebars/handlebars_in_html_feature.test b/tests/languages/handlebars/handlebars_in_html_feature.test new file mode 100644 index 0000000000..1c2dafea96 --- /dev/null +++ b/tests/languages/handlebars/handlebars_in_html_feature.test @@ -0,0 +1,273 @@ +{{aUserModel.name}} +
{{listOfUsers.firstObject.name}}
+{{if name "I have a name" "I have no name"}} + +
+---------------------------------------------------- + +[ + [ + "handlebars", + [ + [ + "delimiter", + "{{" + ], + [ + "variable", + "aUserModel" + ], + [ + "punctuation", + "." + ], + [ + "variable", + "name" + ], + [ + "delimiter", + "}}" + ] + ] + ], + [ + "tag", + [ + [ + "tag", + [ + [ + "punctuation", + "<" + ], + "div" + ] + ], + [ + "punctuation", + ">" + ] + ] + ], + [ + "handlebars", + [ + [ + "delimiter", + "{{" + ], + [ + "variable", + "listOfUsers" + ], + [ + "punctuation", + "." + ], + [ + "variable", + "firstObject" + ], + [ + "punctuation", + "." + ], + [ + "variable", + "name" + ], + [ + "delimiter", + "}}" + ] + ] + ], + [ + "tag", + [ + [ + "tag", + [ + [ + "punctuation", + "" + ] + ] + ], + [ + "handlebars", + [ + [ + "delimiter", + "{{" + ], + [ + "variable", + "if" + ], + [ + "variable", + "name" + ], + [ + "string", + "\"I have a name\"" + ], + [ + "string", + "\"I have no name\"" + ], + [ + "delimiter", + "}}" + ] + ] + ], + [ + "tag", + [ + [ + "tag", + [ + [ + "punctuation", + "<" + ], + "span" + ] + ], + [ + "attr-name", + [ + "data-has-name" + ] + ], + [ + "attr-value", + [ + [ + "punctuation", + "=" + ], + [ + "handlebars", + [ + [ + "delimiter", + "{{" + ], + [ + "variable", + "if" + ], + [ + "variable", + "name" + ], + [ + "boolean", + "true" + ], + [ + "delimiter", + "}}" + ] + ] + ] + ] + ], + [ + "punctuation", + ">" + ] + ] + ], + [ + "tag", + [ + [ + "tag", + [ + [ + "punctuation", + "" + ] + ] + ], + [ + "tag", + [ + [ + "tag", + [ + [ + "punctuation", + "<" + ], + "div" + ] + ], + [ + "attr-name", + [ + [ + "handlebars", + [ + [ + "delimiter", + "{{" + ], + [ + "variable", + "on" + ], + [ + "string", + "\"click\"" + ], + [ + "variable", + "this" + ], + [ + "punctuation", + "." + ], + [ + "variable", + "hello" + ], + [ + "delimiter", + "}}" + ] + ] + ] + ] + ], + [ + "punctuation", + "/>" + ] + ] + ] +] + +---------------------------------------------------- + +Checks for handlebars filter in Html. \ No newline at end of file diff --git a/tests/languages/handlebars/punctuation_feature.test b/tests/languages/handlebars/punctuation_feature.test new file mode 100644 index 0000000000..8276813b78 --- /dev/null +++ b/tests/languages/handlebars/punctuation_feature.test @@ -0,0 +1,31 @@ +{{~#if isActive~}}{{~/if~}} +{{:slot-name}} +---------------------------------------------------- + +[ + ["handlebars", [ + ["delimiter", "{{"], + ["punctuation", "~"], + ["block", "#if"], + ["variable", "isActive"], + ["punctuation", "~"], + ["delimiter", "}}"] + ]], + ["handlebars", [ + ["delimiter", "{{"], + ["punctuation", "~"], + ["block", "/if"], + ["punctuation", "~"], + ["delimiter", "}}"] + ]], + ["handlebars", [ + ["delimiter", "{{"], + ["punctuation", ":"], + ["variable", "slot-name"], + ["delimiter", "}}"] + ]] +] + +---------------------------------------------------- + +Checks for punctuation. \ No newline at end of file diff --git a/tests/languages/handlebars/variable_feature.test b/tests/languages/handlebars/variable_feature.test new file mode 100644 index 0000000000..31f94da80c --- /dev/null +++ b/tests/languages/handlebars/variable_feature.test @@ -0,0 +1,21 @@ +{{comments}} +{{@comments}} +{{this.comments}} + +---------------------------------------------------- + +[ + ["handlebars",[ + ["delimiter","{{"],["variable","comments"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["punctuation","@"],["variable","comments"],["delimiter","}}"]] + ], + ["handlebars",[ + ["delimiter","{{"],["variable","this"],["punctuation","."],["variable","comments"],["delimiter","}}"]] + ] +] + +---------------------------------------------------- + +Checks for variable. \ No newline at end of file