diff options
| author | Matthäus G. Chajdas <dev@anteru.net> | 2022-12-04 15:41:42 +0100 |
|---|---|---|
| committer | Matthäus G. Chajdas <dev@anteru.net> | 2022-12-04 15:41:42 +0100 |
| commit | 607fba8c7221507d845735adac93e71d4970d27d (patch) | |
| tree | 230ff99e029e88cc5e9b7f6a18b5b182441a79bd | |
| parent | c1fe7bb1ad2c04f894f90b23090fa854794d63ac (diff) | |
| download | pygments-git-607fba8c7221507d845735adac93e71d4970d27d.tar.gz | |
Improve whitespace handling in Markdown.
| -rw-r--r-- | pygments/lexers/markup.py | 8 | ||||
| -rw-r--r-- | tests/examplefiles/md/example.md.output | 16 | ||||
| -rw-r--r-- | tests/snippets/md/test_bulleted_list_1.txt | 4 | ||||
| -rw-r--r-- | tests/snippets/md/test_bulleted_list_2.txt | 4 | ||||
| -rw-r--r-- | tests/snippets/md/test_bulleted_list_3.txt | 4 | ||||
| -rw-r--r-- | tests/snippets/md/test_bulleted_list_4.txt | 4 | ||||
| -rw-r--r-- | tests/snippets/md/test_inline_code_after_block.txt | 4 | ||||
| -rw-r--r-- | tests/snippets/md/test_inline_code_in_list.txt | 8 | ||||
| -rw-r--r-- | tests/snippets/md/test_task_list.txt | 4 |
9 files changed, 28 insertions, 28 deletions
diff --git a/pygments/lexers/markup.py b/pygments/lexers/markup.py index 47feaeb6..4fdfc1a1 100644 --- a/pygments/lexers/markup.py +++ b/pygments/lexers/markup.py @@ -17,7 +17,7 @@ from pygments.lexers.css import CssLexer from pygments.lexer import RegexLexer, DelegatingLexer, include, bygroups, \ using, this, do_insertions, default, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Generic, Other + Number, Punctuation, Generic, Other, Whitespace from pygments.util import get_bool_opt, ClassNotFound __all__ = ['BBCodeLexer', 'MoinWikiLexer', 'RstLexer', 'TexLexer', 'GroffLexer', @@ -549,13 +549,13 @@ class MarkdownLexer(RegexLexer): (r'^(.+)(\n)(-+)(\n)', bygroups(Generic.Subheading, Text, Generic.Subheading, Text)), # task list (r'^(\s*)([*-] )(\[[ xX]\])( .+\n)', - bygroups(Text, Keyword, Keyword, using(this, state='inline'))), + bygroups(Whitespace, Keyword, Keyword, using(this, state='inline'))), # bulleted list (r'^(\s*)([*-])(\s)(.+\n)', - bygroups(Text, Keyword, Text, using(this, state='inline'))), + bygroups(Whitespace, Keyword, Whitespace, using(this, state='inline'))), # numbered list (r'^(\s*)([0-9]+\.)( .+\n)', - bygroups(Text, Keyword, using(this, state='inline'))), + bygroups(Whitespace, Keyword, using(this, state='inline'))), # quote (r'^(\s*>\s)(.+\n)', bygroups(Keyword, Generic.Emph)), # code block fenced by 3 backticks diff --git a/tests/examplefiles/md/example.md.output b/tests/examplefiles/md/example.md.output index e027e5f3..57a20e95 100644 --- a/tests/examplefiles/md/example.md.output +++ b/tests/examplefiles/md/example.md.output @@ -6,10 +6,10 @@ '## this is a 2nd level header' Generic.Subheading '\n' Text -'\n' Text +'\n' Text.Whitespace '*' Keyword -' ' Text +' ' Text.Whitespace 'list' Text ' ' Text 'item' Text @@ -17,9 +17,9 @@ '1' Text '\n' Text -' ' Text +' ' Text.Whitespace '*' Keyword -' ' Text +' ' Text.Whitespace 'list' Text ' ' Text 'item' Text @@ -28,7 +28,7 @@ '\n' Text '*' Keyword -' ' Text +' ' Text.Whitespace 'list' Text ' ' Text 'item' Text @@ -37,7 +37,7 @@ '\n' Text '-' Keyword -' ' Text +' ' Text.Whitespace 'list' Text ' ' Text 'item' Text @@ -45,7 +45,7 @@ '3' Text '\n' Text -'\n' Text +'\n' Text.Whitespace '1.' Keyword ' ' Text @@ -69,7 +69,7 @@ '2' Text '\n' Text -'\n' Text +'\n' Text.Whitespace '- ' Keyword '[ ]' Keyword diff --git a/tests/snippets/md/test_bulleted_list_1.txt b/tests/snippets/md/test_bulleted_list_1.txt index 6bb58fbe..553d7be1 100644 --- a/tests/snippets/md/test_bulleted_list_1.txt +++ b/tests/snippets/md/test_bulleted_list_1.txt @@ -4,11 +4,11 @@ ---tokens--- '*' Keyword -' ' Text +' ' Text.Whitespace 'foo' Text '\n' Text '*' Keyword -' ' Text +' ' Text.Whitespace 'bar' Text '\n' Text diff --git a/tests/snippets/md/test_bulleted_list_2.txt b/tests/snippets/md/test_bulleted_list_2.txt index 9283611d..c097a254 100644 --- a/tests/snippets/md/test_bulleted_list_2.txt +++ b/tests/snippets/md/test_bulleted_list_2.txt @@ -4,11 +4,11 @@ ---tokens--- '-' Keyword -' ' Text +' ' Text.Whitespace 'foo' Text '\n' Text '-' Keyword -' ' Text +' ' Text.Whitespace 'bar' Text '\n' Text diff --git a/tests/snippets/md/test_bulleted_list_3.txt b/tests/snippets/md/test_bulleted_list_3.txt index b7142007..2e9b925b 100644 --- a/tests/snippets/md/test_bulleted_list_3.txt +++ b/tests/snippets/md/test_bulleted_list_3.txt @@ -4,11 +4,11 @@ ---tokens--- '*' Keyword -' ' Text +' ' Text.Whitespace '*foo*' Generic.Emph '\n' Text '*' Keyword -' ' Text +' ' Text.Whitespace 'bar' Text '\n' Text diff --git a/tests/snippets/md/test_bulleted_list_4.txt b/tests/snippets/md/test_bulleted_list_4.txt index fe29d0a6..6451ebf1 100644 --- a/tests/snippets/md/test_bulleted_list_4.txt +++ b/tests/snippets/md/test_bulleted_list_4.txt @@ -9,11 +9,11 @@ code '```\ncode\n```\n' Literal.String.Backtick '*' Keyword -' ' Text +' ' Text.Whitespace '*foo*' Generic.Emph '\n' Text '*' Keyword -' ' Text +' ' Text.Whitespace 'bar' Text '\n' Text diff --git a/tests/snippets/md/test_inline_code_after_block.txt b/tests/snippets/md/test_inline_code_after_block.txt index 9be80acf..085d0c12 100644 --- a/tests/snippets/md/test_inline_code_after_block.txt +++ b/tests/snippets/md/test_inline_code_after_block.txt @@ -9,11 +9,11 @@ code '```\ncode\n```\n' Literal.String.Backtick '*' Keyword -' ' Text +' ' Text.Whitespace 'nocode' Text '\n' Text '*' Keyword -' ' Text +' ' Text.Whitespace '`code`' Literal.String.Backtick '\n' Text diff --git a/tests/snippets/md/test_inline_code_in_list.txt b/tests/snippets/md/test_inline_code_in_list.txt index 643f0e5d..096c974b 100644 --- a/tests/snippets/md/test_inline_code_in_list.txt +++ b/tests/snippets/md/test_inline_code_in_list.txt @@ -7,18 +7,18 @@ ---tokens--- '*' Keyword -' ' Text +' ' Text.Whitespace '`code`' Literal.String.Backtick '\n' Text -'\n' Text +'\n' Text.Whitespace '-' Keyword -' ' Text +' ' Text.Whitespace '`code`' Literal.String.Backtick '\n' Text -'\n' Text +'\n' Text.Whitespace '1.' Keyword ' ' Text diff --git a/tests/snippets/md/test_task_list.txt b/tests/snippets/md/test_task_list.txt index e821ff8e..8f83cdf7 100644 --- a/tests/snippets/md/test_task_list.txt +++ b/tests/snippets/md/test_task_list.txt @@ -14,7 +14,7 @@ 'task' Text '\n' Text -'\n' Text +'\n' Text.Whitespace '* ' Keyword '[ ]' Keyword @@ -24,7 +24,7 @@ 'task' Text '\n' Text -'\n ' Text +'\n ' Text.Whitespace '* ' Keyword '[ ]' Keyword ' ' Text |
