Anonymous avatar Anonymous committed 2114284

Support Haml multiline notation.

Comments (0)

Files changed (1)

pygments/lexers/web.py

     mimetypes = ['text/x-haml']
 
     flags = re.IGNORECASE
+    # Haml can include " |\n" anywhere,
+    # which is ignored and used to wrap long lines.
+    # To accomodate this, use this custom faux dot instead.
+    _dot = r'(?: \|\n(?=.* \|)|.)'
     tokens = {
         'root': [
             (r'[ \t]*\n', Text),
 
         'eval-or-plain': [
             (r'[&!]?==', Punctuation, 'plain'),
-            (r'([&!]?[=~])(.*\n)',
+            (r'([&!]?[=~])(' + _dot + '*\n)',
              bygroups(Punctuation, using(RubyLexer)),
              'root'),
             (r'', Text, 'plain'),
         'content': [
             include('css'),
             (r'%[a-z0-9_:-]+', Name.Tag, 'tag'),
-            (r'!!!.*\n', Name.Namespace, '#pop'),
-            (r'(/)(\[.*?\])(.*\n)',
+            (r'!!!' + _dot + '*\n', Name.Namespace, '#pop'),
+            (r'(/)(\[' + _dot + '*?\])(' + _dot + '*\n)',
              bygroups(Comment, Comment.Special, Comment),
              '#pop'),
-            (r'/.*\n', _starts_block(Comment, 'html-comment-block'), '#pop'),
-            (r'-#.*\n', _starts_block(Comment.Preproc, 'haml-comment-block'), '#pop'),
-            (r'(-)(.*\n)',
+            (r'/' + _dot + '*\n', _starts_block(Comment, 'html-comment-block'), '#pop'),
+            (r'-#' + _dot + '*\n', _starts_block(Comment.Preproc, 'haml-comment-block'), '#pop'),
+            (r'(-)(' + _dot + '*\n)',
              bygroups(Punctuation, using(RubyLexer)),
              '#pop'),
-            (r':.*\n', _starts_block(Name.Decorator, 'filter-block'), '#pop'),
+            (r':' + _dot + '*\n', _starts_block(Name.Decorator, 'filter-block'), '#pop'),
             include('eval-or-plain'),
         ],
 
         'tag': [
             include('css'),
-            (r'\{(.|,\n)*?\}', using(RubyLexer)),
-            (r'\[.*?\]', using(RubyLexer)),
+            (r'\{(,\n|' + _dot + ')*?\}', using(RubyLexer)),
+            (r'\[' + _dot + '*?\]', using(RubyLexer)),
             (r'\(', Text, 'html-attributes'),
             (r'/[ \t]*\n', Punctuation, '#pop:2'),
             (r'[<>]{1,2}(?=[ \t=])', Punctuation),
 
         'plain': [
             (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Text),
-            (r'(#\{)(.*?)(\})',
+            (r'(#\{)(' + _dot + '*?)(\})',
              bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
             (r'\n', Text, 'root'),
         ],
         ],
 
         'html-comment-block': [
-            (r'.+', Comment),
+            (_dot + '+', Comment),
             (r'\n', Text, 'root'),
         ],
 
         'haml-comment-block': [
-            (r'.+', Comment.Preproc),
+            (_dot + '+', Comment.Preproc),
             (r'\n', Text, 'root'),
         ],
 
         'filter-block': [
             (r'([^#\n]|#[^{\n]|(\\\\)*\\#\{)+', Name.Decorator),
-            (r'(#\{)(.*?)(\})',
+            (r'(#\{)(' + _dot + '*?)(\})',
              bygroups(String.Interpol, using(RubyLexer), String.Interpol)),
             (r'\n', Text, 'root'),
         ],
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.