diff options
author | Mark Lautman <mlautman@perfectsensedigital.com> | 2018-07-05 11:35:11 -0400 |
---|---|---|
committer | Mark Lautman <mlautman@perfectsensedigital.com> | 2018-07-05 11:35:11 -0400 |
commit | 139ec15dd20d1c5daee2c3d0bae23c4b835e15a4 (patch) | |
tree | c7a1ab53349dc8e627ef48ac2abf853d4e1134f3 | |
parent | 0db8e281af377923115b894703b2b8beb8f1e9d5 (diff) | |
download | pygments-139ec15dd20d1c5daee2c3d0bae23c4b835e15a4.tar.gz |
Add robustness to Handlebars laxer.
-rw-r--r-- | pygments/lexers/templates.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 83c57db8..72e4ffa3 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -1802,27 +1802,25 @@ class HandlebarsLexer(RegexLexer): 'root': [ (r'[^{]+', Other), + # Comment start {{! }} or {{!-- (r'\{\{!.*\}\}', Comment), + # HTML Escaping open {{{expression (r'(\{\{\{)(\s*)', bygroups(Comment.Special, Text), 'tag'), + # {{blockOpen {{#blockOpen {{/blockClose with optional ~ + (r'(\{\{)([#~/]+)([^\s}]*)', bygroups(Comment.Preproc, Number.Attribute,Number.Attribute), 'tag'), (r'(\{\{)(\s*)', bygroups(Comment.Preproc, Text), 'tag'), ], 'tag': [ (r'\s+', Text), + # HTML Escaping close }}} (r'\}\}\}', Comment.Special, '#pop'), - (r'\}\}', Comment.Preproc, '#pop'), - - # Handlebars - (r'([#/]*)(each|if|unless|else|with|log|in(line)?)', bygroups(Keyword, - Keyword)), - (r'#\*inline', Keyword), - - # General {{#block}} - (r'([#/])([\w-]+)', bygroups(Name.Function, Name.Function)), + # blockClose}}, includes optional tilde ~ + (r'(~?)(\}\})', bygroups(Number, Comment.Preproc), '#pop'), # {{opt=something}} - (r'([\w-]+)(=)', bygroups(Name.Attribute, Operator)), + (r'([^\s}]+)(=)', bygroups(Name.Attribute, Operator)), # Partials {{> ...}} (r'(>)(\s*)(@partial-block)', bygroups(Keyword, Text, Keyword)), @@ -1845,7 +1843,7 @@ class HandlebarsLexer(RegexLexer): include('generic'), ], 'variable': [ - (r'[a-zA-Z][\w-]*', Name.Variable), + (r'[()/@a-zA-Z][\w-]*', Name.Variable), (r'\.[\w-]+', Name.Variable), (r'(this\/|\.\/|(\.\.\/)+)[\w-]+', Name.Variable), ], |