Commits

Anonymous committed 301c97d

[svn] added jinja support to django lexer

  • Participants
  • Parent commits 15d12e1
  • Branches trunk

Comments (0)

Files changed (2)

pygments/lexers/_mapping.py

     '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',)),
     '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',)),
     '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',)),
     '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',), ()),

pygments/lexers/templates.py

 
 
 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,
             (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),
         ],
         '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)
             rv += 0.1
         return rv
 
-class GenshiTextLexer(RegexLexer):
-    aliases = ['genshitext']
 
 class GenshiTextLexer(RegexLexer):
     name = 'Genshi Text'
 
 
 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)
 
 
 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)
 
 
 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,