3 pygments.lexers.templates |
3 pygments.lexers.templates |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for various template engines' markup. |
6 Lexers for various template engines' markup. |
7 |
7 |
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. |
9 :license: BSD, see LICENSE for details. |
9 :license: BSD, see LICENSE for details. |
10 """ |
10 """ |
11 |
11 |
12 import re |
12 import re |
13 |
13 |
367 (r'(_|true|false|none|True|False|None)\b', Keyword.Pseudo), |
367 (r'(_|true|false|none|True|False|None)\b', Keyword.Pseudo), |
368 (r'(in|as|reversed|recursive|not|and|or|is|if|else|import|' |
368 (r'(in|as|reversed|recursive|not|and|or|is|if|else|import|' |
369 r'with(?:(?:out)?\s*context)?|scoped|ignore\s+missing)\b', |
369 r'with(?:(?:out)?\s*context)?|scoped|ignore\s+missing)\b', |
370 Keyword), |
370 Keyword), |
371 (r'(loop|block|super|forloop)\b', Name.Builtin), |
371 (r'(loop|block|super|forloop)\b', Name.Builtin), |
372 (r'[a-zA-Z][\w-]*', Name.Variable), |
372 (r'[a-zA-Z_][\w-]*', Name.Variable), |
373 (r'\.\w+', Name.Variable), |
373 (r'\.\w+', Name.Variable), |
374 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
374 (r':?"(\\\\|\\"|[^"])*"', String.Double), |
375 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
375 (r":?'(\\\\|\\'|[^'])*'", String.Single), |
376 (r'([{}()\[\]+\-*/,:~]|[><=]=?)', Operator), |
376 (r'([{}()\[\]+\-*/,:~]|[><=]=?)', Operator), |
377 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
377 (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" |
566 )""", bygroups(using(HtmlLexer), Operator)), |
566 )""", bygroups(using(HtmlLexer), Operator)), |
567 ] |
567 ] |
568 } |
568 } |
569 |
569 |
570 def analyse_text(text): |
570 def analyse_text(text): |
571 rv = 0.0 |
571 result = 0.0 |
572 if re.search('<&', text) is not None: |
572 if re.search(r'</%(class|doc|init)%>', text) is not None: |
573 rv = 1.0 |
573 result = 1.0 |
574 return rv |
574 elif re.search(r'<&.+&>', text, re.DOTALL) is not None: |
|
575 result = 0.11 |
|
576 return result |
575 |
577 |
576 |
578 |
577 class MakoLexer(RegexLexer): |
579 class MakoLexer(RegexLexer): |
578 """ |
580 """ |
579 Generic `mako templates`_ lexer. Code that isn't Mako |
581 Generic `mako templates`_ lexer. Code that isn't Mako |
1776 super(LassoJavascriptLexer, self).__init__(JavascriptLexer, LassoLexer, |
1778 super(LassoJavascriptLexer, self).__init__(JavascriptLexer, LassoLexer, |
1777 **options) |
1779 **options) |
1778 |
1780 |
1779 def analyse_text(text): |
1781 def analyse_text(text): |
1780 rv = LassoLexer.analyse_text(text) - 0.05 |
1782 rv = LassoLexer.analyse_text(text) - 0.05 |
1781 if 'function' in text: |
|
1782 rv += 0.2 |
|
1783 return rv |
1783 return rv |
1784 |
1784 |
1785 |
1785 |
1786 class HandlebarsLexer(RegexLexer): |
1786 class HandlebarsLexer(RegexLexer): |
1787 """ |
1787 """ |