diff options
-rw-r--r-- | pygments/lexers/_mapping.py | 10 | ||||
-rw-r--r-- | pygments/lexers/templates.py | 46 |
2 files changed, 29 insertions, 27 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 83c0dc96..4268435d 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -19,7 +19,7 @@ LEXERS = { 'CLexer': ('pygments.lexers.compiled', 'C', ('c',), ('*.c', '*.h')), 'CSharpLexer': ('pygments.lexers.dotnet', 'C#', ('csharp', 'c#'), ('*.cs',)), 'CppLexer': ('pygments.lexers.compiled', 'C++', ('cpp', 'c++'), ('*.cpp', '*.hpp', '*.c++', '*.h++')), - 'CssDjangoLexer': ('pygments.lexers.templates', 'CSS+Django', ('css+django',), ()), + 'CssDjangoLexer': ('pygments.lexers.templates', 'CSS+Django/Jinja', ('css+django', 'css+jinja'), ()), 'CssErbLexer': ('pygments.lexers.templates', 'CSS+Ruby', ('css+erb', 'css+ruby'), ()), 'CssGenshiLexer': ('pygments.lexers.templates', 'CSS+Genshi Text', ('css+genshitext', 'css+genshi'), ()), 'CssLexer': ('pygments.lexers.web', 'CSS', ('css',), ('*.css',)), @@ -27,11 +27,11 @@ LEXERS = { 'CssSmartyLexer': ('pygments.lexers.templates', 'CSS+Smarty', ('css+smarty',), ()), 'DelphiLexer': ('pygments.lexers.compiled', 'Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas',)), 'DiffLexer': ('pygments.lexers.text', 'Diff', ('diff',), ('*.diff', '*.patch')), - 'DjangoLexer': ('pygments.lexers.templates', 'django template', ('django',), ()), + 'DjangoLexer': ('pygments.lexers.templates', 'Django/Jinja', ('django', 'jinja'), ()), 'ErbLexer': ('pygments.lexers.templates', 'ERB', ('erb',), ()), 'GenshiLexer': ('pygments.lexers.templates', 'Genshi', ('genshi', 'kid', 'xml+genshi', 'xml+kid'), ('*.kid',)), 'GenshiTextLexer': ('pygments.lexers.templates', 'Genshi Text', ('genshitext',), ()), - 'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django', ('html+django',), ()), + 'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django/Jinja', ('html+django', 'html+jinja'), ()), 'HtmlGenshiLexer': ('pygments.lexers.templates', 'HTML+Genshi', ('html+genshi', 'html+kid'), ()), 'HtmlLexer': ('pygments.lexers.web', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml')), 'HtmlPhpLexer': ('pygments.lexers.templates', 'HTML+PHP', ('html+php',), ('*.phtml',)), @@ -39,7 +39,7 @@ LEXERS = { 'IniLexer': ('pygments.lexers.text', 'INI', ('ini', 'cfg'), ('*.ini', '*.cfg')), 'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), ()), 'JavaLexer': ('pygments.lexers.compiled', 'Java', ('java',), ('*.java',)), - 'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django', ('js+django', 'javascript+django'), ()), + 'JavascriptDjangoLexer': ('pygments.lexers.templates', 'JavaScript+Django/Jinja', ('js+django', 'javascript+django', 'js+jinja', 'javascript+jinja'), ()), 'JavascriptErbLexer': ('pygments.lexers.templates', 'JavaScript+Ruby', ('js+erb', 'javascript+erb', 'js+ruby', 'javascript+ruby'), ()), 'JavascriptGenshiLexer': ('pygments.lexers.templates', 'JavaScript+Genshi Text', ('js+genshitext', 'js+genshi', 'javascript+genshitext', 'javascript+genshi'), ()), 'JavascriptLexer': ('pygments.lexers.web', 'JavaScript', ('js', 'javascript'), ('*.js',)), @@ -60,7 +60,7 @@ LEXERS = { 'TexLexer': ('pygments.lexers.text', 'TeX', ('tex', 'latex'), ('*.tex', '*.aux', '*.toc')), 'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('*.txt',)), 'VbNetLexer': ('pygments.lexers.dotnet', 'VB.net', ('vb.net', 'vbnet'), ('*.vb', '*.bas')), - 'XmlDjangoLexer': ('pygments.lexers.templates', 'XML+Django', ('xml+django',), ()), + 'XmlDjangoLexer': ('pygments.lexers.templates', 'XML+Django/Jinja', ('xml+django', 'xml+jinja'), ()), 'XmlErbLexer': ('pygments.lexers.templates', 'XML+Ruby', ('xml+erb', 'xml+ruby'), ()), 'XmlLexer': ('pygments.lexers.web', 'XML', ('xml',), ('*.xml',)), 'XmlPhpLexer': ('pygments.lexers.templates', 'XML+PHP', ('xml+php',), ()), diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index d2f17343..99d5ba48 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -166,13 +166,16 @@ class SmartyLexer(RegexLexer): class DjangoLexer(RegexLexer): - name = 'django template' - aliases = ['django'] + name = 'Django/Jinja' + aliases = ['django', 'jinja'] tokens = { 'root': [ (r'[^\{]+', Other), (r'\{\{', Comment.Preproc, 'var'), + # jinja comments + (r'\{\*.*?\*\}', Comment), + # django comments (r'(\{\%)(\s*)(comment)(\s*)(\%\})(.*?)' r'(\{\%)(\s*)(endcomment)(\s*)(\%\})', bygroups(Comment.Preproc, Text, Keyword, Text, Comment.Preproc, @@ -183,13 +186,14 @@ class DjangoLexer(RegexLexer): (r'\{', Other) ], 'varnames': [ - (r'[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*', Name.Variable), - (r"(\|)([a-zA-Z_][a-zA-Z0-9_]*)(:'(\\\\|\\'|[^'])*')", - bygroups(Operator, Name.Function, String.Single)), - (r'(\|)([a-zA-Z_][a-zA-Z0-9_]*)(:"(\\\\|\\"|[^"])*")', - bygroups(Operator, Name.Function, String.Double)), - (r'(\|)([a-zA-Z_][a-zA-Z0-9_]*)', - bygroups(Operator, Name.Function)) + (r'[a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*', + Name.Variable), + (r'(\|)(\s*)([a-zA-Z_][a-zA-Z0-9_]*)', + bygroups(Operator, Text, Name.Function)), + (r':?"(\\\\|\\"|[^"])*"', String.Double), + (r":?'(\\\\|\\'|[^'])*'", String.Single), + (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|" + r"0[xX][0-9a-fA-F]+[Ll]?", Number), ], 'var': [ (r'\s+', Text), @@ -198,9 +202,8 @@ class DjangoLexer(RegexLexer): ], 'block': [ (r'\s+', Text), - (r'(in|as|reversed|not|count|and|or|with)\b', Keyword), - (r'"(\\\\|\\"|[^"])*"', String.Double), - (r"'(\\\\|\\'|[^'])*'", String.Single), + (r'(in|as|reversed|not|count|and|or|with|equals|accepting)\b', + Keyword), include('varnames'), (r'\%\}', Comment.Preproc, '#pop'), (r'.', Text) @@ -217,8 +220,6 @@ class DjangoLexer(RegexLexer): rv += 0.1 return rv -class GenshiTextLexer(RegexLexer): - aliases = ['genshitext'] class GenshiTextLexer(RegexLexer): name = 'Genshi Text' @@ -502,8 +503,8 @@ class JavascriptSmartyLexer(DelegatingLexer): class HtmlDjangoLexer(DelegatingLexer): - name = 'HTML+Django' - aliases = ['html+django'] + name = 'HTML+Django/Jinja' + aliases = ['html+django', 'html+jinja'] def __init__(self, **options): super(HtmlDjangoLexer, self).__init__(HtmlLexer, DjangoLexer, **options) @@ -516,8 +517,8 @@ class HtmlDjangoLexer(DelegatingLexer): class XmlDjangoLexer(DelegatingLexer): - name = 'XML+Django' - aliases = ['xml+django'] + name = 'XML+Django/Jinja' + aliases = ['xml+django', 'xml+jinja'] def __init__(self, **options): super(XmlDjangoLexer, self).__init__(XmlLexer, DjangoLexer, **options) @@ -530,16 +531,17 @@ class XmlDjangoLexer(DelegatingLexer): class CssDjangoLexer(DelegatingLexer): - name = 'CSS+Django' - aliases = ['css+django'] + name = 'CSS+Django/Jinja' + aliases = ['css+django', 'css+jinja'] def __init__(self, **options): super(CssDjangoLexer, self).__init__(CssLexer, DjangoLexer, **options) class JavascriptDjangoLexer(DelegatingLexer): - name = 'JavaScript+Django' - aliases = ['js+django', 'javascript+django'] + name = 'JavaScript+Django/Jinja' + aliases = ['js+django', 'javascript+django', + 'js+jinja', 'javascript+jinja'] def __init__(self, **options): super(JavascriptDjangoLexer, self).__init__(JavascriptLexer, DjangoLexer, |