diff options
author | Matthäus G. Chajdas <dev@anteru.net> | 2021-11-13 21:07:57 +0100 |
---|---|---|
committer | Matthäus G. Chajdas <dev@anteru.net> | 2021-11-13 21:07:57 +0100 |
commit | 337dddef92b69d3a1e88fa450bef55149d24c1d9 (patch) | |
tree | e0d21003d3406f4ec3f81bde47f9f7285a4b9e02 | |
parent | 798cd36cb49a3dcbb3d3b0e1cb61598ce81a1acc (diff) | |
download | pygments-git-337dddef92b69d3a1e88fa450bef55149d24c1d9.tar.gz |
Fix #1896.
Use a simpler expression to match comments in HTML/XML.
-rw-r--r-- | pygments/lexers/html.py | 16 | ||||
-rw-r--r-- | tests/examplefiles/duel/jbst_example1.jbst.output | 4 | ||||
-rw-r--r-- | tests/examplefiles/duel/jbst_example2.jbst.output | 8 | ||||
-rw-r--r-- | tests/examplefiles/genshi/genshi_example.xml+genshi.output | 4 | ||||
-rw-r--r-- | tests/examplefiles/html+handlebars/demo.hbs.output | 4 | ||||
-rw-r--r-- | tests/examplefiles/html/example.xhtml.output | 14 | ||||
-rw-r--r-- | tests/examplefiles/jsp/test.jsp.output | 6 | ||||
-rw-r--r-- | tests/examplefiles/xml/xml_example.output | 50 |
8 files changed, 24 insertions, 82 deletions
diff --git a/pygments/lexers/html.py b/pygments/lexers/html.py index aab83025..2e29f453 100644 --- a/pygments/lexers/html.py +++ b/pygments/lexers/html.py @@ -42,7 +42,7 @@ class HtmlLexer(RegexLexer): ('[^<&]+', Text), (r'&\S*?;', Name.Entity), (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), - ('<!--', Comment, 'comment'), + (r'<!--(.|\n)*?-->', Comment.Multiline), (r'<\?.*?\?>', Comment.Preproc), ('<![^>]*>', Comment.Preproc), (r'(<)(\s*)(script)(\s*)', @@ -59,11 +59,6 @@ class HtmlLexer(RegexLexer): bygroups(Punctuation, Text, Punctuation, Text, Name.Tag, Text, Punctuation)), ], - 'comment': [ - ('[^-]+', Comment), - ('-->', Comment, '#pop'), - ('-', Comment), - ], 'tag': [ (r'\s+', Text), (r'([\w:-]+\s*)(=)(\s*)', bygroups(Name.Attribute, Operator, Text), @@ -213,18 +208,13 @@ class XmlLexer(RegexLexer): 'root': [ ('[^<&]+', Text), (r'&\S*?;', Name.Entity), - (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), - ('<!--', Comment, 'comment'), + (r'\<\!\[CDATA\[.*?\]\]\>', Comment.Preproc), + (r'<!--(.|\n)*?-->', Comment.Multiline), (r'<\?.*?\?>', Comment.Preproc), ('<![^>]*>', Comment.Preproc), (r'<\s*[\w:.-]+', Name.Tag, 'tag'), (r'<\s*/\s*[\w:.-]+\s*>', Name.Tag), ], - 'comment': [ - ('[^-]+', Comment), - ('-->', Comment, '#pop'), - ('-', Comment), - ], 'tag': [ (r'\s+', Text), (r'[\w.:-]+\s*=', Name.Attribute, 'attr'), diff --git a/tests/examplefiles/duel/jbst_example1.jbst.output b/tests/examplefiles/duel/jbst_example1.jbst.output index a5b6b3fa..2474f3ad 100644 --- a/tests/examplefiles/duel/jbst_example1.jbst.output +++ b/tests/examplefiles/duel/jbst_example1.jbst.output @@ -163,9 +163,7 @@ '>' Punctuation '\n\n' Text -'<!--' Comment -' HTML Comment ' Comment -'-->' Comment +'<!-- HTML Comment -->' Comment.Multiline '\n' Text '<' Punctuation diff --git a/tests/examplefiles/duel/jbst_example2.jbst.output b/tests/examplefiles/duel/jbst_example2.jbst.output index e3c4d488..36eb214d 100644 --- a/tests/examplefiles/duel/jbst_example2.jbst.output +++ b/tests/examplefiles/duel/jbst_example2.jbst.output @@ -320,9 +320,7 @@ ' ' Text '%>' Name.Tag '">\n\n\t\t' Text -'<!--' Comment -' anonymous inner template ' Comment -'-->' Comment +'<!-- anonymous inner template -->' Comment.Multiline '\n\t\t' Text '<' Punctuation 'jbst:control' Name.Tag @@ -341,9 +339,7 @@ ' ' Text '%>' Name.Tag '">\n\t\t\t' Text -'<!--' Comment -" populate list item for each item of the parent's children property " Comment -'-->' Comment +"<!-- populate list item for each item of the parent's children property -->" Comment.Multiline '\n\t\t\t' Text '<' Punctuation 'li' Name.Tag diff --git a/tests/examplefiles/genshi/genshi_example.xml+genshi.output b/tests/examplefiles/genshi/genshi_example.xml+genshi.output index 48d096ee..bc9ccce8 100644 --- a/tests/examplefiles/genshi/genshi_example.xml+genshi.output +++ b/tests/examplefiles/genshi/genshi_example.xml+genshi.output @@ -520,9 +520,7 @@ '\n ' Text '<py:otherwise' Name.Tag '>' Name.Tag -'<!--' Comment -'! not the first line of a multiline constraint ' Comment -'-->' Comment +'<!--! not the first line of a multiline constraint -->' Comment.Multiline '\n ' Text '<th' Name.Tag ' ' Text diff --git a/tests/examplefiles/html+handlebars/demo.hbs.output b/tests/examplefiles/html+handlebars/demo.hbs.output index baef672b..d01b72b0 100644 --- a/tests/examplefiles/html+handlebars/demo.hbs.output +++ b/tests/examplefiles/html+handlebars/demo.hbs.output @@ -1,6 +1,4 @@ -'<!--' Comment -' post.handlebars ' Comment -'-->' Comment +'<!-- post.handlebars -->' Comment.Multiline '\n\n' Text '<' Punctuation diff --git a/tests/examplefiles/html/example.xhtml.output b/tests/examplefiles/html/example.xhtml.output index acceed24..90979e44 100644 --- a/tests/examplefiles/html/example.xhtml.output +++ b/tests/examplefiles/html/example.xhtml.output @@ -2514,9 +2514,7 @@ 'div' Name.Tag '>' Punctuation ' ' Text -'<!--' Comment -' #cloud ' Comment -'-->' Comment +'<!-- #cloud -->' Comment.Multiline '\n ' Text '<?r end ?>' Comment.Preproc '\n ' Text @@ -2525,9 +2523,7 @@ 'div' Name.Tag '>' Punctuation ' ' Text -'<!--' Comment -' #left ' Comment -'-->' Comment +'<!-- #left -->' Comment.Multiline '\n \n ' Text '<' Punctuation 'render' Name.Tag @@ -2546,9 +2542,5 @@ '>' Punctuation '\n\n' Text -'<!--' Comment -' Copyright © 2006 Kashia Buch (kashia@vfemail.net), Fabian Buch (fabian@fabian' Comment -'-' Comment -'buch.de). All rights reserved. ' Comment -'-->' Comment +'<!-- Copyright © 2006 Kashia Buch (kashia@vfemail.net), Fabian Buch (fabian@fabian-buch.de). All rights reserved. -->' Comment.Multiline '\n' Text diff --git a/tests/examplefiles/jsp/test.jsp.output b/tests/examplefiles/jsp/test.jsp.output index a09da5a9..6b2fb003 100644 --- a/tests/examplefiles/jsp/test.jsp.output +++ b/tests/examplefiles/jsp/test.jsp.output @@ -1,5 +1,4 @@ -'<!--' Comment -' This page was loaded on ' Comment +'<!-- This page was loaded on ' Comment.Multiline '<%=' Keyword ' ' Text '(' Punctuation @@ -19,8 +18,7 @@ ')' Punctuation ' ' Text '%>' Keyword -' ' Comment -'-->' Comment +' -->' Comment.Multiline '\n' Text '<%=' Keyword diff --git a/tests/examplefiles/xml/xml_example.output b/tests/examplefiles/xml/xml_example.output index 3cd69c2f..df7af59c 100644 --- a/tests/examplefiles/xml/xml_example.output +++ b/tests/examplefiles/xml/xml_example.output @@ -5466,9 +5466,7 @@ '"dsOthers"' Literal.String '/>' Name.Tag ' ' Text -'<!--' Comment -',Qt::darkYellow,Qt::yellow,false,false)); ' Comment -'-->' Comment +'<!--,Qt::darkYellow,Qt::yellow,false,false)); -->' Comment.Multiline '\n ' Text '</itemDatas>' Name.Tag '\n ' Text @@ -12280,60 +12278,34 @@ '<!DOCTYPE language SYSTEM "language.dtd">' Comment.Preproc '\n' Text -'<!--' Comment -' Author: Werner Braun <wb@o3' Comment -'-' Comment -'software.de> ' Comment -'-->' Comment +'<!-- Author: Werner Braun <wb@o3-software.de> -->' Comment.Multiline '\n' Text -'<!--' Comment -' 29.05.2003 wb mailed to the kate' Comment -'-' Comment -'team (cullmann) ' Comment -'-->' Comment +'<!-- 29.05.2003 wb mailed to the kate-team (cullmann) -->' Comment.Multiline '\n' Text -'<!--' Comment -' 23.05.2003 wb added *.bro File' Comment -'-' Comment -'Type for GPCP Browser output' Comment -'-->' Comment +'<!-- 23.05.2003 wb added *.bro File-Type for GPCP Browser output-->' Comment.Multiline '\n' Text -'<!--' Comment -' 09.05.2003 wb nested comments allowed (maximum two level nesting) ' Comment -'-->' Comment +'<!-- 09.05.2003 wb nested comments allowed (maximum two level nesting) -->' Comment.Multiline '\n' Text -'<!--' Comment -' 07.04.2003 wb IN Problem solved ' Comment -'-->' Comment +'<!-- 07.04.2003 wb IN Problem solved -->' Comment.Multiline '\n' Text -'<!--' Comment -' 06.05.2003 wb NEW without ( ' Comment -'-->' Comment +'<!-- 06.05.2003 wb NEW without ( -->' Comment.Multiline '\n' Text -'<!--' Comment -' 22.04.2003 wb Minor bugfixes ' Comment -'-->' Comment +'<!-- 22.04.2003 wb Minor bugfixes -->' Comment.Multiline '\n' Text -'<!--' Comment -' 19.04.2003 wb Some more Enhancements ' Comment -'-->' Comment +'<!-- 19.04.2003 wb Some more Enhancements -->' Comment.Multiline '\n' Text -'<!--' Comment -' 18.04.2003 wb Enhancenment for Maior / Minor Comments and Full / ReadOnly Exports, Folds for Procedures, Records, Comments ' Comment -'-->' Comment +'<!-- 18.04.2003 wb Enhancenment for Maior / Minor Comments and Full / ReadOnly Exports, Folds for Procedures, Records, Comments -->' Comment.Multiline '\n' Text -'<!--' Comment -' 17.04.2003 wb Enhancements for Relation and Operators ' Comment -'-->' Comment +'<!-- 17.04.2003 wb Enhancements for Relation and Operators -->' Comment.Multiline '\n' Text '<language' Name.Tag |