From 63acfb1caf387cbb7db992ff153d7d1bcc51c6f7 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Thu, 2 Jan 2020 23:33:08 +0100 Subject: [PATCH 01/15] wip: adjustments for integrating handlebars rules - hash-parameters - subexpressions wip: adjustments for integrating handlebars rules - hash-parameters - subexpressions wip: update tests some minor adaptions wip: fix test cases wip: try to honor path expressions correctly wip: fix tests and refactor language definition wip: update keywords, remove debug output wip: {{else}} is a keyword and not a helper call wip: fix test for else-variants - else is not a built-in (except for the keyword {{else}}) wip: fix hashes and number literals, add string literals - the hash-value must start after the equals-sign - number and string modes must be in front of identifiers, because they are a subset wip: make "as" in block-parameters a "keyword" fixup: revert tests to old tests from origin/master fixup: adjust expected test results for failing tests add else variant tests --- src/languages/handlebars.js | 144 +++++++++++++++--- src/languages/htmlbars.js | 86 ----------- test/detect/htmlbars/default.txt | 9 -- ...ck-expression-variants-in-param.expect.txt | 4 +- test/markup/handlebars/built-ins.expect.txt | 4 +- test/markup/handlebars/comments.expect.txt | 2 +- .../handlebars/escaped-mustaches.expect.txt | 6 +- .../handlebars/expression-variants.expect.txt | 24 +-- .../markup/handlebars/partial-call.expect.txt | 2 +- test/markup/handlebars/raw-block.expect.txt | 2 +- .../handlebars/simple-expression.expect.txt | 2 +- .../handlebars/sub-expressions.expect.txt | 2 +- .../handlebars/triple-mustache.expect.txt | 2 +- 13 files changed, 148 insertions(+), 141 deletions(-) delete mode 100644 src/languages/htmlbars.js delete mode 100644 test/detect/htmlbars/default.txt diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index 7fea1c3cca..e502113b8f 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -6,31 +6,125 @@ Description: Matcher for Handlebars as well as EmberJS additions. Website: https://handlebarsjs.com Category: template */ +export default function (hljs) { -export default function(hljs) { - var BUILT_INS = {'builtin-name': 'each in with if else unless bindattr action collection debugger log outlet template unbound view yield lookup'}; + var BUILT_INS = { + 'builtin-name': 'action bindattr collection component concat debugger ' + + 'each each-in get hash if in input link-to loc log lookup ' + + 'mut outlet partial query-params render template textarea unbound ' + + 'unless view with yield' + }; - var IDENTIFIER_PLAIN_OR_QUOTED = { - begin: /".*?"|'.*?'|\[.*?\]|\w+/ + var LITERALS = { + 'literal': 'true false undefined null' }; - var EXPRESSION_OR_HELPER_CALL = hljs.inherit(IDENTIFIER_PLAIN_OR_QUOTED, { - keywords: BUILT_INS, + // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments + // this regex matches literal segments like ' abc ' or [ abc ] as well as helpers and paths + // like a/b, ./abc/cde, and abc.bcd + var IDENFIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; + + // identifier followed by a equal-sign (without the equal sign) + var HASH_PARAM_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; + + var HELPER_NAME_OR_PATH_EXPRESSION = { + begin: IDENFIFIER_REGEX, + lexemes: /[\w.\/]+/ + }; + + var HELPER_PARAMETER = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + keywords: LITERALS + }); + + var SUB_EXPRESSION = { + illegal: /\}\}/, + begin: /\(/, end: /\)/ + // the "contains" is added below when all necessary sub-modes are defined + }; + + var HASH = { + // fka "attribute-assignment", parameters of the form 'key=value' + className: 'attr', + illegal: /\}\}/, + begin: HASH_PARAM_REGEX, + relevance: 0, starts: { - // helper params - endsWithParent: true, - relevance: 0, - contains: [hljs.inherit(IDENTIFIER_PLAIN_OR_QUOTED, {relevance: 0})] + begin: /=/, + end: /=/, + starts: { + contains: [ + hljs.NUMBER_MODE, + hljs.QUOTE_STRING_MODE, + hljs.APOS_STRING_MODE, + HELPER_PARAMETER, + SUB_EXPRESSION + ] + } } + }; + + var BLOCK_PARAMS = { + // parameters of the form '{{#with x as | y |}}...{{/with}}' + begin: /as\s+\|/, + keywords: { keyword: 'as' }, + end: /\|/, + contains: [ + { + // define sub-mode in order to prevent highlighting of block-parameter named "as" + begin: /\w+/, + keywords: '' + } + ] + } + + var HELPER_PARAMETERS = { + contains: [ + hljs.NUMBER_MODE, + hljs.QUOTE_STRING_MODE, + hljs.APOS_STRING_MODE, + BLOCK_PARAMS, + HASH, + HELPER_PARAMETER, + SUB_EXPRESSION + ], + returnEnd: true + // the property "end" is defined through inheritance when the mode is used. If depends + // on the surrounding mode, but "endsWithParent" does not work here (i.e. it includes the + // end-token of the surrounding mode) + }; + + var SUB_EXPRESSION_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + className: 'name', + keywords: BUILT_INS, + starts: hljs.inherit(HELPER_PARAMETERS, { + end: /\)/, + }) + }); + + SUB_EXPRESSION.contains = [ + SUB_EXPRESSION_CONTENTS + ]; + + var OPENING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + keywords: BUILT_INS, + className: 'name', + starts: hljs.inherit(HELPER_PARAMETERS, { + end: /}}/, + }) }); - var BLOCK_MUSTACHE_CONTENTS = hljs.inherit(EXPRESSION_OR_HELPER_CALL, { + var CLOSING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + keywords: BUILT_INS, className: 'name' }); - var BASIC_MUSTACHE_CONTENTS = hljs.inherit(EXPRESSION_OR_HELPER_CALL, { - // relevance 0 for backward compatibility concerning auto-detection - relevance: 0 + + var BASIC_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + className: 'name', + keywords: BUILT_INS, + starts: hljs.inherit(HELPER_PARAMETERS, { + end: /}}/, + }) }); var ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH = {begin: /\\\{\{/, skip: true}; @@ -38,7 +132,7 @@ export default function(hljs) { return { name: 'Handlebars', - aliases: ['hbs', 'html.hbs', 'html.handlebars'], + aliases: ['hbs', 'html.hbs', 'html.handlebars', 'htmlbars'], case_insensitive: true, subLanguage: 'xml', contains: [ @@ -50,33 +144,41 @@ export default function(hljs) { // open raw block "{{{{raw}}}} content not evaluated {{{{/raw}}}}" className: 'template-tag', begin: /\{\{\{\{(?!\/)/, end: /\}\}\}\}/, - contains: [BLOCK_MUSTACHE_CONTENTS], + contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], starts: {end: /\{\{\{\{\//, returnEnd: true, subLanguage: 'xml'} }, { // close raw block className: 'template-tag', begin: /\{\{\{\{\//, end: /\}\}\}\}/, - contains: [BLOCK_MUSTACHE_CONTENTS] + contains: [CLOSING_BLOCK_MUSTACHE_CONTENTS] }, { // open block statement className: 'template-tag', - begin: /\{\{[#\/]/, end: /\}\}/, - contains: [BLOCK_MUSTACHE_CONTENTS], + begin: /\{\{#/, end: /\}\}/, + contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], + }, + { + className: 'keyword', + begin: /\{\{else\}\}/ + }, + { + // closing block statement + className: 'template-tag', + begin: /\{\{\//, end: /\}\}/, + contains: [CLOSING_BLOCK_MUSTACHE_CONTENTS], }, { // template variable or helper-call that is NOT html-escaped className: 'template-variable', begin: /\{\{\{/, end: /\}\}\}/, - keywords: BUILT_INS, contains: [BASIC_MUSTACHE_CONTENTS] }, { // template variable or helper-call that is html-escaped className: 'template-variable', begin: /\{\{/, end: /\}\}/, - keywords: BUILT_INS, contains: [BASIC_MUSTACHE_CONTENTS] } ] diff --git a/src/languages/htmlbars.js b/src/languages/htmlbars.js deleted file mode 100644 index 11a4488107..0000000000 --- a/src/languages/htmlbars.js +++ /dev/null @@ -1,86 +0,0 @@ -/* -Language: HTMLBars -Requires: xml.js, handlebars.js -Author: Michael Johnston -Description: Matcher for HTMLBars -Website: https://github.com/tildeio/htmlbars -Category: template -*/ - -export default function(hljs) { - // This work isn't complete yet but this is done so that this technically - // breaking change becomes a part of the 10.0 release and won't force - // us to prematurely release 11.0 just to break this. - var SHOULD_INHERIT_FROM_HANDLEBARS = hljs.requireLanguage('handlebars'); - // https://github.com/highlightjs/highlight.js/issues/2181 - - var BUILT_INS = 'action collection component concat debugger each each-in else get hash if input link-to loc log mut outlet partial query-params render textarea unbound unless with yield view'; - - var ATTR_ASSIGNMENT = { - illegal: /\}\}/, - begin: /[a-zA-Z0-9_]+=/, - returnBegin: true, - relevance: 0, - contains: [ - { - className: 'attr', begin: /[a-zA-Z0-9_]+/ - } - ] - }; - - var SUB_EXPR = { - illegal: /\}\}/, - begin: /\)/, end: /\)/, - contains: [ - { - begin: /[a-zA-Z\.\-]+/, - keywords: {built_in: BUILT_INS}, - starts: { - endsWithParent: true, relevance: 0, - contains: [ - hljs.QUOTE_STRING_MODE, - ] - } - } - ] - }; - - var TAG_INNARDS = { - endsWithParent: true, relevance: 0, - keywords: {keyword: 'as', built_in: BUILT_INS}, - contains: [ - hljs.QUOTE_STRING_MODE, - ATTR_ASSIGNMENT, - hljs.NUMBER_MODE - ] - }; - - return { - name: 'HTMLBars', - case_insensitive: true, - subLanguage: 'xml', - contains: [ - hljs.COMMENT('{{!(--)?', '(--)?}}'), - { - className: 'template-tag', - begin: /\{\{[#\/]/, end: /\}\}/, - contains: [ - { - className: 'name', - begin: /[a-zA-Z\.\-]+/, - keywords: {'builtin-name': BUILT_INS}, - starts: TAG_INNARDS - } - ] - }, - { - className: 'template-variable', - begin: /\{\{[a-zA-Z][a-zA-Z\-]+/, end: /\}\}/, - keywords: {keyword: 'as', built_in: BUILT_INS}, - contains: [ - hljs.QUOTE_STRING_MODE - ] - } - ] - }; -} diff --git a/test/detect/htmlbars/default.txt b/test/detect/htmlbars/default.txt deleted file mode 100644 index c3003aef0a..0000000000 --- a/test/detect/htmlbars/default.txt +++ /dev/null @@ -1,9 +0,0 @@ -
- {{!-- only output this author names if an author exists --}} - {{#if author}} - {{#playwright-wrapper playwright=author action=(mut author) as |playwright|}} -

{{playwright.firstName}} {{playwright.lastName}}

- {{/playwright-wrapper}} - {{/if}} - {{yield}} -
diff --git a/test/markup/handlebars/block-expression-variants-in-param.expect.txt b/test/markup/handlebars/block-expression-variants-in-param.expect.txt index ae081bc79b..1d6250a0a8 100644 --- a/test/markup/handlebars/block-expression-variants-in-param.expect.txt +++ b/test/markup/handlebars/block-expression-variants-in-param.expect.txt @@ -1,6 +1,6 @@ -text {{#abc "lite]'ral}}segment" }}a{{/abc}} +text {{#abc "lite]'ral}}segment" }}a{{/abc}} -text {{#abc 'lite]"ral}}segment' }}a{{/abc}} +text {{#abc 'lite]"ral}}segment' }}a{{/abc}} text {{#abc [lite"'ral}}segment] }}a{{/abc}} diff --git a/test/markup/handlebars/built-ins.expect.txt b/test/markup/handlebars/built-ins.expect.txt index cedd3aa3e6..06b6df66a8 100644 --- a/test/markup/handlebars/built-ins.expect.txt +++ b/test/markup/handlebars/built-ins.expect.txt @@ -6,7 +6,7 @@ {{#each test}}abc{{/each}} -{{lookup abc}} +{{lookup abc}} -{{log test}} +{{log test}} diff --git a/test/markup/handlebars/comments.expect.txt b/test/markup/handlebars/comments.expect.txt index d1dbff8968..e8f3741766 100644 --- a/test/markup/handlebars/comments.expect.txt +++ b/test/markup/handlebars/comments.expect.txt @@ -1,4 +1,4 @@ -{{!-- a comment {{expression}} --}} {{expression}} +{{!-- a comment {{expression}} --}} {{expression}} {{! a simple comment }} diff --git a/test/markup/handlebars/escaped-mustaches.expect.txt b/test/markup/handlebars/escaped-mustaches.expect.txt index da37eb1812..d56ec49a6a 100644 --- a/test/markup/handlebars/escaped-mustaches.expect.txt +++ b/test/markup/handlebars/escaped-mustaches.expect.txt @@ -12,11 +12,11 @@ <!-- escaped escapings --> -\\{{expression}} +\\{{expression}} -\\\{{expression}} +\\\{{expression}} -\\\\{{expression}} +\\\\{{expression}} \\\{{! comment }} diff --git a/test/markup/handlebars/expression-variants.expect.txt b/test/markup/handlebars/expression-variants.expect.txt index 48da6b13c7..dd1c2d9814 100644 --- a/test/markup/handlebars/expression-variants.expect.txt +++ b/test/markup/handlebars/expression-variants.expect.txt @@ -1,27 +1,27 @@ text -{{ "lite]'ral}}segment" }} text +{{ "lite]'ral}}segment" }} text -{{ 'lite]"ral}}segment' }} text +{{ 'lite]"ral}}segment' }} text -{{ [lite"'ral}}segment] }} text +{{ [lite"'ral}}segment] }} text -{{ abc "lite]'ral}}segment" }} text +{{ abc "lite]'ral}}segment" }} text -{{ abc 'lite]"ral}}segment' }} text +{{ abc 'lite]"ral}}segment' }} text -{{ abc [lite"'ral}}segment] }} text +{{ abc [lite"'ral}}segment] }} text -{{ abcd.[lite"'ral}}segment] }} text +{{ abcd.[lite"'ral}}segment] }} text -{{ abcd."lite]'ral}}segment" }} text +{{ abcd."lite]'ral}}segment" }} text -{{ abcd.'lite]"ral}}segment' }} text +{{ abcd.'lite]"ral}}segment' }} text -{{ abcd.''}} text +{{ abcd.''}} text -{{ abcd."" }} text +{{ abcd."" }} text -{{ abcd.[] }} text +{{ abcd.[] }} text diff --git a/test/markup/handlebars/partial-call.expect.txt b/test/markup/handlebars/partial-call.expect.txt index 139b33a8f4..506dfef8fc 100644 --- a/test/markup/handlebars/partial-call.expect.txt +++ b/test/markup/handlebars/partial-call.expect.txt @@ -1,2 +1,2 @@ -{{> partial}} +{{> partial}} diff --git a/test/markup/handlebars/raw-block.expect.txt b/test/markup/handlebars/raw-block.expect.txt index 93b0a0558d..b5d94e8a34 100644 --- a/test/markup/handlebars/raw-block.expect.txt +++ b/test/markup/handlebars/raw-block.expect.txt @@ -1,2 +1,2 @@ -{{{{#raw}}}} {{verbatim}} content {{{{/raw}}}} {{var}} +{{{{#raw}}}} {{verbatim}} content {{{{/raw}}}} {{var}} diff --git a/test/markup/handlebars/simple-expression.expect.txt b/test/markup/handlebars/simple-expression.expect.txt index c243c13ba1..41d5cc869f 100644 --- a/test/markup/handlebars/simple-expression.expect.txt +++ b/test/markup/handlebars/simple-expression.expect.txt @@ -1,2 +1,2 @@ -{{abc}} +{{abc}} diff --git a/test/markup/handlebars/sub-expressions.expect.txt b/test/markup/handlebars/sub-expressions.expect.txt index d8bf1c4c32..8fe21d0b10 100644 --- a/test/markup/handlebars/sub-expressions.expect.txt +++ b/test/markup/handlebars/sub-expressions.expect.txt @@ -1,2 +1,2 @@ -{{helper (subExpression 1 2)}} +{{helper (subExpression 1 2)}} diff --git a/test/markup/handlebars/triple-mustache.expect.txt b/test/markup/handlebars/triple-mustache.expect.txt index b2fb748b97..3512548e3f 100644 --- a/test/markup/handlebars/triple-mustache.expect.txt +++ b/test/markup/handlebars/triple-mustache.expect.txt @@ -1,2 +1,2 @@ -{{{raw}}} +{{{raw}}} From a0a56111a51c6ef21ba8fbd74b06ffa7d7642c5d Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sat, 11 Apr 2020 00:35:09 +0200 Subject: [PATCH 02/15] fixup: add more tests add else variant tests fixup --- .../handlebars/block-parameters-as.expect.txt | 4 ++++ test/markup/handlebars/block-parameters-as.txt | 3 +++ .../handlebars/combinations-with-text.expect.txt | 6 ++++++ test/markup/handlebars/combinations-with-text.txt | 5 +++++ test/markup/handlebars/else-variants.expect.txt | 11 +++++++++++ test/markup/handlebars/else-variants.txt | 10 ++++++++++ test/markup/handlebars/hashes.expect.txt | 12 ++++++++++++ test/markup/handlebars/hashes.txt | 11 +++++++++++ .../literals-in-different-places.expect.txt | 14 ++++++++++++++ .../handlebars/literals-in-different-places.txt | 13 +++++++++++++ test/markup/handlebars/literals.expect.txt | 14 ++++++++++++++ test/markup/handlebars/literals.txt | 13 +++++++++++++ test/markup/handlebars/path-expressions.expect.txt | 10 ++++++++++ test/markup/handlebars/path-expressions.txt | 9 +++++++++ test/markup/handlebars/sub-expressions.expect.txt | 12 ++++++++++++ test/markup/handlebars/sub-expressions.txt | 12 ++++++++++++ 16 files changed, 159 insertions(+) create mode 100644 test/markup/handlebars/block-parameters-as.expect.txt create mode 100644 test/markup/handlebars/block-parameters-as.txt create mode 100644 test/markup/handlebars/combinations-with-text.expect.txt create mode 100644 test/markup/handlebars/combinations-with-text.txt create mode 100644 test/markup/handlebars/else-variants.expect.txt create mode 100644 test/markup/handlebars/else-variants.txt create mode 100644 test/markup/handlebars/hashes.expect.txt create mode 100644 test/markup/handlebars/hashes.txt create mode 100644 test/markup/handlebars/literals-in-different-places.expect.txt create mode 100644 test/markup/handlebars/literals-in-different-places.txt create mode 100644 test/markup/handlebars/literals.expect.txt create mode 100644 test/markup/handlebars/literals.txt create mode 100644 test/markup/handlebars/path-expressions.expect.txt create mode 100644 test/markup/handlebars/path-expressions.txt diff --git a/test/markup/handlebars/block-parameters-as.expect.txt b/test/markup/handlebars/block-parameters-as.expect.txt new file mode 100644 index 0000000000..87547011c7 --- /dev/null +++ b/test/markup/handlebars/block-parameters-as.expect.txt @@ -0,0 +1,4 @@ +{{#each filter as | value index|}} {{/each}} + +{{#with as as | as |}} {{/with}} + diff --git a/test/markup/handlebars/block-parameters-as.txt b/test/markup/handlebars/block-parameters-as.txt new file mode 100644 index 0000000000..4f696ef7af --- /dev/null +++ b/test/markup/handlebars/block-parameters-as.txt @@ -0,0 +1,3 @@ +{{#each filter as | value index|}} {{/each}} + +{{#with as as | as |}} {{/with}} diff --git a/test/markup/handlebars/combinations-with-text.expect.txt b/test/markup/handlebars/combinations-with-text.expect.txt new file mode 100644 index 0000000000..383bea58a6 --- /dev/null +++ b/test/markup/handlebars/combinations-with-text.expect.txt @@ -0,0 +1,6 @@ +some text + +{{#custom (nested (helper 'a{{bc' 1)) key=value as | blockParam |}} some {{blockParam}} text {{/custom}} + +some text + diff --git a/test/markup/handlebars/combinations-with-text.txt b/test/markup/handlebars/combinations-with-text.txt new file mode 100644 index 0000000000..a30fdf882a --- /dev/null +++ b/test/markup/handlebars/combinations-with-text.txt @@ -0,0 +1,5 @@ +some text + +{{#custom (nested (helper 'a{{bc' 1)) key=value as | blockParam |}} some {{blockParam}} text {{/custom}} + +some text diff --git a/test/markup/handlebars/else-variants.expect.txt b/test/markup/handlebars/else-variants.expect.txt new file mode 100644 index 0000000000..79416da520 --- /dev/null +++ b/test/markup/handlebars/else-variants.expect.txt @@ -0,0 +1,11 @@ +{{#helper}}{{else}}else-block{{/helper}} + +{{#helper}}block{{else}}else-block{{/helper}} + +{{[else]}} in brackets is a helper, not a keyword + +{{#else}} as block helper name is not a keyword {{/else}} + +\{{else}} is not a keyword if escaped + + diff --git a/test/markup/handlebars/else-variants.txt b/test/markup/handlebars/else-variants.txt new file mode 100644 index 0000000000..1f9365c83c --- /dev/null +++ b/test/markup/handlebars/else-variants.txt @@ -0,0 +1,10 @@ +{{#helper}}{{else}}else-block{{/helper}} + +{{#helper}}block{{else}}else-block{{/helper}} + +{{[else]}} in brackets is a helper, not a keyword + +{{#else}} as block helper name is not a keyword {{/else}} + +\{{else}} is not a keyword if escaped + diff --git a/test/markup/handlebars/hashes.expect.txt b/test/markup/handlebars/hashes.expect.txt new file mode 100644 index 0000000000..ddf626e066 --- /dev/null +++ b/test/markup/handlebars/hashes.expect.txt @@ -0,0 +1,12 @@ +{{helper key=value}} + +{{{helper key=value}}} + +{{>partial key=value}} + +{{#helper key=value}} {{/helper}} + +{{{{#helper key=value}}}} {{{{/helper}}}} + +{{helper (subExpression key=value)}} + diff --git a/test/markup/handlebars/hashes.txt b/test/markup/handlebars/hashes.txt new file mode 100644 index 0000000000..6c63673b89 --- /dev/null +++ b/test/markup/handlebars/hashes.txt @@ -0,0 +1,11 @@ +{{helper key=value}} + +{{{helper key=value}}} + +{{>partial key=value}} + +{{#helper key=value}} {{/helper}} + +{{{{#helper key=value}}}} {{{{/helper}}}} + +{{helper (subExpression key=value)}} diff --git a/test/markup/handlebars/literals-in-different-places.expect.txt b/test/markup/handlebars/literals-in-different-places.expect.txt new file mode 100644 index 0000000000..a82bd9f8d7 --- /dev/null +++ b/test/markup/handlebars/literals-in-different-places.expect.txt @@ -0,0 +1,14 @@ +{{helper true false a=true b=false}} + +{{{helper true false}}} + +{{#helper true false}} {{/helper}} + +{{{{#helper true false}}}} {{{{/helper}}}} + +{{>partial true}} + +{{helper (helper true false)}} + +{{helper a=true b=false}} + diff --git a/test/markup/handlebars/literals-in-different-places.txt b/test/markup/handlebars/literals-in-different-places.txt new file mode 100644 index 0000000000..da8fe7ce60 --- /dev/null +++ b/test/markup/handlebars/literals-in-different-places.txt @@ -0,0 +1,13 @@ +{{helper true false a=true b=false}} + +{{{helper true false}}} + +{{#helper true false}} {{/helper}} + +{{{{#helper true false}}}} {{{{/helper}}}} + +{{>partial true}} + +{{helper (helper true false)}} + +{{helper a=true b=false}} diff --git a/test/markup/handlebars/literals.expect.txt b/test/markup/handlebars/literals.expect.txt new file mode 100644 index 0000000000..65cfda721f --- /dev/null +++ b/test/markup/handlebars/literals.expect.txt @@ -0,0 +1,14 @@ +{{helper true false}} + +{{helper 1234}} + +{{helper null}} + +{{helper undefined}} + +{{helper 'string'}} + +{{helper "string"}} + +{{helper [not a string literal but a variable]}} + diff --git a/test/markup/handlebars/literals.txt b/test/markup/handlebars/literals.txt new file mode 100644 index 0000000000..622c80f246 --- /dev/null +++ b/test/markup/handlebars/literals.txt @@ -0,0 +1,13 @@ +{{helper true false}} + +{{helper 1234}} + +{{helper null}} + +{{helper undefined}} + +{{helper 'string'}} + +{{helper "string"}} + +{{helper [not a string literal but a variable]}} diff --git a/test/markup/handlebars/path-expressions.expect.txt b/test/markup/handlebars/path-expressions.expect.txt new file mode 100644 index 0000000000..b5307b1830 --- /dev/null +++ b/test/markup/handlebars/path-expressions.expect.txt @@ -0,0 +1,10 @@ +{{path.expression}} + +{{{path.expression}}} + +{{#path.expression}} {{/path.expression}} + +{{{{#path.expression}}}} {{{{/path.expression}}}} + +{{with.in.a.path.expression}} is not a built-in + diff --git a/test/markup/handlebars/path-expressions.txt b/test/markup/handlebars/path-expressions.txt new file mode 100644 index 0000000000..c898318e07 --- /dev/null +++ b/test/markup/handlebars/path-expressions.txt @@ -0,0 +1,9 @@ +{{path.expression}} + +{{{path.expression}}} + +{{#path.expression}} {{/path.expression}} + +{{{{#path.expression}}}} {{{{/path.expression}}}} + +{{with.in.a.path.expression}} is not a built-in diff --git a/test/markup/handlebars/sub-expressions.expect.txt b/test/markup/handlebars/sub-expressions.expect.txt index 8fe21d0b10..6b386b9c3c 100644 --- a/test/markup/handlebars/sub-expressions.expect.txt +++ b/test/markup/handlebars/sub-expressions.expect.txt @@ -1,2 +1,14 @@ {{helper (subExpression 1 2)}} + +{{{helper (subExpression 1 2)}}} + +{{{{#helper (subExpression 1 2)}}}} {{{{/helper}}}} + +{{#helper (subExpression 1 2)}} {{/helper}} + +{{>partial (subExpression 1 2)}} + +{{helper key=(subExpression 1 2)}} + +{{helper (subExpression (canBeNested 1 2) anotherParam)}} diff --git a/test/markup/handlebars/sub-expressions.txt b/test/markup/handlebars/sub-expressions.txt index 55f2b34547..737c2967fd 100644 --- a/test/markup/handlebars/sub-expressions.txt +++ b/test/markup/handlebars/sub-expressions.txt @@ -1 +1,13 @@ {{helper (subExpression 1 2)}} + +{{{helper (subExpression 1 2)}}} + +{{{{#helper (subExpression 1 2)}}}} {{{{/helper}}}} + +{{#helper (subExpression 1 2)}} {{/helper}} + +{{>partial (subExpression 1 2)}} + +{{helper key=(subExpression 1 2)}} + +{{helper (subExpression (canBeNested 1 2) anotherParam)}} From 193f4c27bd4f60ddc978f2575afb5984a61fbe53 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Fri, 31 Jan 2020 22:21:24 +0100 Subject: [PATCH 03/15] fixup: make only "else" in {{else}} the keywords, not "{{else}}" as whole --- src/languages/handlebars.js | 6 ++++-- test/markup/handlebars/else-variants.expect.txt | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index e502113b8f..0936bbbb00 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -160,8 +160,10 @@ export default function (hljs) { contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], }, { - className: 'keyword', - begin: /\{\{else\}\}/ + className: 'template-tag', + begin: /\{\{(?=else\}\})/, + end: /\}\}/, + keywords: 'else' }, { // closing block statement diff --git a/test/markup/handlebars/else-variants.expect.txt b/test/markup/handlebars/else-variants.expect.txt index 79416da520..55bc49d22c 100644 --- a/test/markup/handlebars/else-variants.expect.txt +++ b/test/markup/handlebars/else-variants.expect.txt @@ -1,6 +1,6 @@ -{{#helper}}{{else}}else-block{{/helper}} +{{#helper}}{{else}}else-block{{/helper}} -{{#helper}}block{{else}}else-block{{/helper}} +{{#helper}}block{{else}}else-block{{/helper}} {{[else]}} in brackets is a helper, not a keyword From dc0df11beaf0ddbfc81c4e91894dda5ec40f144e Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 13 May 2020 12:37:55 -0400 Subject: [PATCH 04/15] add htmlbars back --- src/languages/htmlbars.js | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/languages/htmlbars.js diff --git a/src/languages/htmlbars.js b/src/languages/htmlbars.js new file mode 100644 index 0000000000..df09b5357d --- /dev/null +++ b/src/languages/htmlbars.js @@ -0,0 +1,42 @@ +/* + Language: HTMLBars (legacy) + Requires: xml.js + Description: Matcher for Handlebars as well as EmberJS additions. + Website: https://github.com/tildeio/htmlbars + Category: template + */ + +/* + +See: https://github.com/highlightjs/highlight.js/issues/2181 + +This file is a stub that is only left in place for compatbility reasons for +anyone who may be manually pulling in this file via a require or fetching +it individually via CDN. + +TODO: Remove in version 11.0. + +*/ + +// compile time dependency on handlebars +import handlebars from "./handlebars" + +export default function(hljs) { + const definition = handlebars(hljs) + + definition.name = "HTMLbars" + + // HACK: This lets handlebars do the auto-detection if it's been loaded (by + // default the build script will load in alphabetical order) and if not (perhaps + // an install is only using `htmlbars`, not `handlebars`) then this will still + // allow HTMLBars to participate in the auto-detection + + // worse case someone will have HTMLbars and handlebars competing for the same + // content and will need to change their setup to only require handlebars, but + // I don't consider this a breaking change + if (hljs.getLanguage("handlebars")) { + definition.disableAutodetect = true + } + + return definition +} From 9c4f581c7c5769c089137bdb581596de891395bd Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 13 May 2020 12:53:29 -0400 Subject: [PATCH 05/15] (chore) move keyword to sep lines --- src/languages/handlebars.js | 43 ++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index 0936bbbb00..5fbd34d4f6 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -6,17 +6,50 @@ Description: Matcher for Handlebars as well as EmberJS additions. Website: https://handlebarsjs.com Category: template */ + export default function (hljs) { var BUILT_INS = { - 'builtin-name': 'action bindattr collection component concat debugger ' - + 'each each-in get hash if in input link-to loc log lookup ' - + 'mut outlet partial query-params render template textarea unbound ' - + 'unless view with yield' + 'builtin-name': [ + 'action', + 'bindattr', + 'collection', + 'component', + 'concat', + 'debugger', + 'each', + 'each-in', + 'get', + 'hash', + 'if', + 'in', + 'input', + 'link-to', + 'loc', + 'log', + 'lookup', + 'mut', + 'outlet', + 'partial', + 'query-params', + 'render', + 'template', + 'textarea', + 'unbound', + 'unless', + 'view', + 'with', + 'yield' + ].join(" ") }; var LITERALS = { - 'literal': 'true false undefined null' + 'literal': [ + 'true', + 'false', + 'undefined', + 'null' + ].join(" ") }; // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments From cdbd6fdaf8f26454d5293e7044fdd8c7b61b1d99 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 13 May 2020 12:54:08 -0400 Subject: [PATCH 06/15] (chore) const vs var --- src/languages/handlebars.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index 5fbd34d4f6..d5dbc918ee 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -9,7 +9,7 @@ Category: template export default function (hljs) { - var BUILT_INS = { + const BUILT_INS = { 'builtin-name': [ 'action', 'bindattr', @@ -43,7 +43,7 @@ export default function (hljs) { ].join(" ") }; - var LITERALS = { + const LITERALS = { 'literal': [ 'true', 'false', @@ -55,27 +55,27 @@ export default function (hljs) { // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments // this regex matches literal segments like ' abc ' or [ abc ] as well as helpers and paths // like a/b, ./abc/cde, and abc.bcd - var IDENFIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; + const IDENFIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; // identifier followed by a equal-sign (without the equal sign) - var HASH_PARAM_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; + const HASH_PARAM_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; - var HELPER_NAME_OR_PATH_EXPRESSION = { + const HELPER_NAME_OR_PATH_EXPRESSION = { begin: IDENFIFIER_REGEX, lexemes: /[\w.\/]+/ }; - var HELPER_PARAMETER = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + const HELPER_PARAMETER = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { keywords: LITERALS }); - var SUB_EXPRESSION = { + const SUB_EXPRESSION = { illegal: /\}\}/, begin: /\(/, end: /\)/ // the "contains" is added below when all necessary sub-modes are defined }; - var HASH = { + const HASH = { // fka "attribute-assignment", parameters of the form 'key=value' className: 'attr', illegal: /\}\}/, @@ -96,7 +96,7 @@ export default function (hljs) { } }; - var BLOCK_PARAMS = { + const BLOCK_PARAMS = { // parameters of the form '{{#with x as | y |}}...{{/with}}' begin: /as\s+\|/, keywords: { keyword: 'as' }, @@ -110,7 +110,7 @@ export default function (hljs) { ] } - var HELPER_PARAMETERS = { + const HELPER_PARAMETERS = { contains: [ hljs.NUMBER_MODE, hljs.QUOTE_STRING_MODE, @@ -126,7 +126,7 @@ export default function (hljs) { // end-token of the surrounding mode) }; - var SUB_EXPRESSION_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + const SUB_EXPRESSION_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { className: 'name', keywords: BUILT_INS, starts: hljs.inherit(HELPER_PARAMETERS, { @@ -138,7 +138,7 @@ export default function (hljs) { SUB_EXPRESSION_CONTENTS ]; - var OPENING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + const OPENING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { keywords: BUILT_INS, className: 'name', starts: hljs.inherit(HELPER_PARAMETERS, { @@ -146,13 +146,13 @@ export default function (hljs) { }) }); - var CLOSING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + const CLOSING_BLOCK_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { keywords: BUILT_INS, className: 'name' }); - var BASIC_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { + const BASIC_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { className: 'name', keywords: BUILT_INS, starts: hljs.inherit(HELPER_PARAMETERS, { @@ -160,8 +160,8 @@ export default function (hljs) { }) }); - var ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH = {begin: /\\\{\{/, skip: true}; - var PREVENT_ESCAPE_WITH_ANOTHER_PRECEEDING_BACKSLASH = {begin: /\\\\(?=\{\{)/, skip: true}; + const ESCAPE_MUSTACHE_WITH_PRECEEDING_BACKSLASH = {begin: /\\\{\{/, skip: true}; + const PREVENT_ESCAPE_WITH_ANOTHER_PRECEEDING_BACKSLASH = {begin: /\\\\(?=\{\{)/, skip: true}; return { name: 'Handlebars', From 88f76a0bd35202e78b0502d3319f7414e03b0e83 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 13 May 2020 12:59:13 -0400 Subject: [PATCH 07/15] (chore) linter --- src/languages/handlebars.js | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index d5dbc918ee..a320df9cd0 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -7,8 +7,7 @@ Website: https://handlebarsjs.com Category: template */ -export default function (hljs) { - +export default function(hljs) { const BUILT_INS = { 'builtin-name': [ 'action', @@ -44,7 +43,7 @@ export default function (hljs) { }; const LITERALS = { - 'literal': [ + literal: [ 'true', 'false', 'undefined', @@ -71,7 +70,8 @@ export default function (hljs) { const SUB_EXPRESSION = { illegal: /\}\}/, - begin: /\(/, end: /\)/ + begin: /\(/, + end: /\)/ // the "contains" is added below when all necessary sub-modes are defined }; @@ -108,7 +108,7 @@ export default function (hljs) { keywords: '' } ] - } + }; const HELPER_PARAMETERS = { contains: [ @@ -151,7 +151,6 @@ export default function (hljs) { className: 'name' }); - const BASIC_MUSTACHE_CONTENTS = hljs.inherit(HELPER_NAME_OR_PATH_EXPRESSION, { className: 'name', keywords: BUILT_INS, @@ -176,20 +175,23 @@ export default function (hljs) { { // open raw block "{{{{raw}}}} content not evaluated {{{{/raw}}}}" className: 'template-tag', - begin: /\{\{\{\{(?!\/)/, end: /\}\}\}\}/, + begin: /\{\{\{\{(?!\/)/, + end: /\}\}\}\}/, contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], starts: {end: /\{\{\{\{\//, returnEnd: true, subLanguage: 'xml'} }, { // close raw block className: 'template-tag', - begin: /\{\{\{\{\//, end: /\}\}\}\}/, + begin: /\{\{\{\{\//, + end: /\}\}\}\}/, contains: [CLOSING_BLOCK_MUSTACHE_CONTENTS] }, { // open block statement className: 'template-tag', - begin: /\{\{#/, end: /\}\}/, + begin: /\{\{#/, + end: /\}\}/, contains: [OPENING_BLOCK_MUSTACHE_CONTENTS], }, { @@ -201,19 +203,22 @@ export default function (hljs) { { // closing block statement className: 'template-tag', - begin: /\{\{\//, end: /\}\}/, + begin: /\{\{\//, + end: /\}\}/, contains: [CLOSING_BLOCK_MUSTACHE_CONTENTS], }, { // template variable or helper-call that is NOT html-escaped className: 'template-variable', - begin: /\{\{\{/, end: /\}\}\}/, + begin: /\{\{\{/, + end: /\}\}\}/, contains: [BASIC_MUSTACHE_CONTENTS] }, { // template variable or helper-call that is html-escaped className: 'template-variable', - begin: /\{\{/, end: /\}\}/, + begin: /\{\{/, + end: /\}\}/, contains: [BASIC_MUSTACHE_CONTENTS] } ] From 74f0c87e6db62e96d564f21d04f5b122f4ffe29f Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 13 May 2020 12:59:13 -0400 Subject: [PATCH 08/15] fixup: fix typo in variable name IDENFIFIER_REGEX --- src/languages/handlebars.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index a320df9cd0..c1442329b4 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -54,13 +54,13 @@ export default function(hljs) { // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments // this regex matches literal segments like ' abc ' or [ abc ] as well as helpers and paths // like a/b, ./abc/cde, and abc.bcd - const IDENFIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; + const IDENTIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; // identifier followed by a equal-sign (without the equal sign) const HASH_PARAM_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; const HELPER_NAME_OR_PATH_EXPRESSION = { - begin: IDENFIFIER_REGEX, + begin: IDENTIFIER_REGEX, lexemes: /[\w.\/]+/ }; From 73a1c66b4d9996d167b001a320bc12df05744eba Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sat, 16 May 2020 23:36:58 +0200 Subject: [PATCH 09/15] fixup: remove `illegal`-regex from SUB_EXPRESSION and `HASH` both never match in a meaningful way. --- src/languages/handlebars.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index c1442329b4..1593b11212 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -69,7 +69,6 @@ export default function(hljs) { }); const SUB_EXPRESSION = { - illegal: /\}\}/, begin: /\(/, end: /\)/ // the "contains" is added below when all necessary sub-modes are defined @@ -78,7 +77,6 @@ export default function(hljs) { const HASH = { // fka "attribute-assignment", parameters of the form 'key=value' className: 'attr', - illegal: /\}\}/, begin: HASH_PARAM_REGEX, relevance: 0, starts: { From c0d7faf704a31598e9dacb5b1bd2fd1122b9a2cb Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sat, 16 May 2020 23:39:52 +0200 Subject: [PATCH 10/15] fixup: remove single and double quotes from HASH_PARAM_REGEX because they are not parsed in hash-keys both never match in a meaningful way. --- src/languages/handlebars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index 1593b11212..a814de6bfa 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -57,7 +57,7 @@ export default function(hljs) { const IDENTIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; // identifier followed by a equal-sign (without the equal sign) - const HASH_PARAM_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; + const HASH_PARAM_REGEX = /(\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; const HELPER_NAME_OR_PATH_EXPRESSION = { begin: IDENTIFIER_REGEX, From 9583704f6a87509f6ae2ee19416b5d0b06b9bbf0 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sat, 16 May 2020 23:56:56 +0200 Subject: [PATCH 11/15] fixup: refactor identifier_regex and hash_param_regex --- src/languages/handlebars.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index a814de6bfa..e1347e4e59 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -7,6 +7,8 @@ Website: https://handlebarsjs.com Category: template */ +import * as regex from '../lib/regex' + export default function(hljs) { const BUILT_INS = { 'builtin-name': [ @@ -54,10 +56,30 @@ export default function(hljs) { // as defined in https://handlebarsjs.com/guide/expressions.html#literal-segments // this regex matches literal segments like ' abc ' or [ abc ] as well as helpers and paths // like a/b, ./abc/cde, and abc.bcd - const IDENTIFIER_REGEX = /(".*?"|'.*?'|\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+|\.|\/)+/; + + const DOUBLE_QUOTED_ID_REGEX=/".*?"/; + const SINGLE_QUOTED_ID_REGEX=/'.*?'/; + const BRACKET_QUOTED_ID_REGEX=/\[.*?\]/; + const PLAIN_ID_REGEX=/[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+/; + const PATH_DELIMITER_REGEX=/\.|\//; + + const IDENTIFIER_REGEX = regex.concat( + '(', + SINGLE_QUOTED_ID_REGEX, '|', + DOUBLE_QUOTED_ID_REGEX, '|', + BRACKET_QUOTED_ID_REGEX, '|', + PLAIN_ID_REGEX, '|', + PATH_DELIMITER_REGEX, + ')+' + ); // identifier followed by a equal-sign (without the equal sign) - const HASH_PARAM_REGEX = /(\[.*?\]|[^\s!"#%&'()*+,.\/;<=>@\[\\\]^`{|}~]+)(?==)/; + const HASH_PARAM_REGEX = regex.concat( + '(', + BRACKET_QUOTED_ID_REGEX, '|', + PLAIN_ID_REGEX, + ')(?==)' + ); const HELPER_NAME_OR_PATH_EXPRESSION = { begin: IDENTIFIER_REGEX, From ad881e412b51881e4134dd4706bea7c759eebce3 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sun, 17 May 2020 00:00:30 +0200 Subject: [PATCH 12/15] docs: fix jsdoc-comment to match the actual expected parameter type --- src/lib/regex.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/regex.js b/src/lib/regex.js index 1727cb57b9..6f2a5967d9 100644 --- a/src/lib/regex.js +++ b/src/lib/regex.js @@ -26,7 +26,7 @@ export function lookahead(re) { } /** - * @param {(RegExp | string)[] } args + * @param {...(RegExp | string) } args * @returns {string} */ export function concat(...args) { From 803fa5b628212f588278e9fe8cfc124ce47d3cb8 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Sun, 17 May 2020 00:15:31 +0200 Subject: [PATCH 13/15] fixup: remove unnecessary "keyword"-property --- src/languages/handlebars.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/languages/handlebars.js b/src/languages/handlebars.js index e1347e4e59..8578982470 100644 --- a/src/languages/handlebars.js +++ b/src/languages/handlebars.js @@ -124,8 +124,7 @@ export default function(hljs) { contains: [ { // define sub-mode in order to prevent highlighting of block-parameter named "as" - begin: /\w+/, - keywords: '' + begin: /\w+/ } ] }; From 5dc0dd0c4e71fae483b3dd14e4d48dc81c0e76d1 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Tue, 19 May 2020 14:57:39 +0200 Subject: [PATCH 14/15] chore: add changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 684bea0c5d..08aff7f3aa 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -37,6 +37,7 @@ Language Improvements: - fix(swift) `@objcMembers` was being partially highlighted (#2543) [Nick Randall][] - enh(dart) Add `late` and `required` keywords, and `Never` built-in type (#2550) [Sam Rawlins][] - enh(erlang) Add underscore separators to numeric literals (#2554) [Sergey Prokhorov][] +- enh(handlebars) Support for sub-expressions, path-expressions, hashes, block-parameters and literals (#2344) [Nils Knappmeier][] [Josh Goebel]: https://github.com/yyyc514 [Peter Plantinga]: https://github.com/pplantinga @@ -46,6 +47,7 @@ Language Improvements: [Nick Randall]: https://github.com/nicked [Sam Rawlins]: https://github.com/srawlins [Sergey Prokhorov]: https://github.com/seriyps +[Nils Knappmeier]: https://github.com/nknapp ## Version 10.0.2 From f664f8f2d4fbc27e8c567c8dcc19848e9aec5290 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Tue, 19 May 2020 10:01:55 -0400 Subject: [PATCH 15/15] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 08aff7f3aa..294ba0defb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ Parser Engine: Deprecations: +- `htmlbars` grammar is now deprecated. Use `handlebars` instead. (#2344) [Nils Knappmeier][] - when using `highlightBlock` `result.re` deprecated. Use `result.relevance` instead. (#2552) [Josh Goebel][] - ditto for `result.second_best.re` => `result.second_best.relevance` (#2552) - `lexemes` is now deprecated in favor of `keywords.$pattern` key (#2519) [Josh Goebel][]