diff options
author | Miikka Salminen <miikka.salminen@gmail.com> | 2015-03-07 22:11:28 +0200 |
---|---|---|
committer | Miikka Salminen <miikka.salminen@gmail.com> | 2015-03-07 22:11:28 +0200 |
commit | 0a78d2678371d0f00ed96dc5fa5da26be12630c4 (patch) | |
tree | 1b6bbca0c02c6a213666252888e2e1c16987d4f3 | |
parent | 50c6950c7fa48cce73af6072b35f40608a158306 (diff) | |
download | pygments-0a78d2678371d0f00ed96dc5fa5da26be12630c4.tar.gz |
HTML lexer now marks angle brackets and slashes as punctuation, and attributes' equal signs as operators.
-rw-r--r-- | pygments/lexers/html.py | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/pygments/lexers/html.py b/pygments/lexers/html.py index 1c35325f..7893952f 100644 --- a/pygments/lexers/html.py +++ b/pygments/lexers/html.py @@ -46,12 +46,19 @@ class HtmlLexer(RegexLexer): ('<!--', Comment, 'comment'), (r'<\?.*?\?>', Comment.Preproc), ('<![^>]*>', Comment.Preproc), - (r'<\s*script\s*', Name.Tag, ('script-content', 'tag')), - (r'<\s*style\s*', Name.Tag, ('style-content', 'tag')), + (r'(<)(\s*)(script)(\s*)', + bygroups(Punctuation, Text, Name.Tag, Text), + ('script-content', 'tag')), + (r'(<)(\s*)(style)(\s*)', + bygroups(Punctuation, Text, Name.Tag, Text), + ('style-content', 'tag')), # note: this allows tag names not used in HTML like <x:with-dash>, # this is to support yet-unknown template engines and the like - (r'<\s*[\w:.-]+', Name.Tag, 'tag'), - (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), + (r'(<)(\s*)([\w:.-]+)', + bygroups(Punctuation, Text, Name.Tag), 'tag'), + (r'(<)(\s*)(/)(\s*)([\w:.-]+)(\s*)(>)', + bygroups(Punctuation, Text, Punctuation, Text, Name.Tag, Text, + Punctuation)), ], 'comment': [ ('[^-]+', Comment), @@ -60,16 +67,21 @@ class HtmlLexer(RegexLexer): ], 'tag': [ (r'\s+', Text), - (r'([\w:-]+\s*=)(\s*)', bygroups(Name.Attribute, Text), 'attr'), + (r'([\w:-]+\s*)(=)(\s*)', bygroups(Name.Attribute, Operator, Text), + 'attr'), (r'[\w:-]+', Name.Attribute), - (r'/?\s*>', Name.Tag, '#pop'), + (r'(/?)(\s*)(>)', bygroups(Punctuation, Text, Punctuation), '#pop'), ], 'script-content': [ - (r'<\s*/\s*script\s*>', Name.Tag, '#pop'), + (r'(<)(\s*)(/)(\s*)(script)(\s*)(>)', + bygroups(Punctuation, Text, Punctuation, Text, Name.Tag, Text, + Punctuation), '#pop'), (r'.+?(?=<\s*/\s*script\s*>)', using(JavascriptLexer)), ], 'style-content': [ - (r'<\s*/\s*style\s*>', Name.Tag, '#pop'), + (r'(<)(\s*)(/)(\s*)(style)(\s*)(>)', + bygroups(Punctuation, Text, Punctuation, Text, Name.Tag, Text, + Punctuation),'#pop'), (r'.+?(?=<\s*/\s*style\s*>)', using(CssLexer)), ], 'attr': [ |