diff options
author | CosmicHorror <LovecraftianHorror@pm.me> | 2023-01-29 15:08:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-29 23:08:40 +0100 |
commit | fdb05f4f309b8cae84b4160ffe404d15d9bd93ef (patch) | |
tree | 8686fddbf3ac3502fa38d457709a69d8287fe479 | |
parent | 4d8bca52b25ba2ae4a5adfdbefcb655f50e3f1f1 (diff) | |
download | pygments-git-fdb05f4f309b8cae84b4160ffe404d15d9bd93ef.tar.gz |
Add support for normal diff syntax (#2321)
-rw-r--r-- | pygments/lexers/diff.py | 13 | ||||
-rw-r--r-- | tests/snippets/diff/normal.txt | 38 | ||||
-rw-r--r-- | tests/snippets/diff/unified.txt | 44 |
3 files changed, 90 insertions, 5 deletions
diff --git a/pygments/lexers/diff.py b/pygments/lexers/diff.py index 6a7ba2f3..cbf52558 100644 --- a/pygments/lexers/diff.py +++ b/pygments/lexers/diff.py @@ -30,13 +30,16 @@ class DiffLexer(RegexLexer): tokens = { 'root': [ (r'( )(.*)(\n)', bygroups(Whitespace, Text, Whitespace)), - (r'(\+.*)(\n)', bygroups(Generic.Inserted, Whitespace)), - (r'(-.*)(\n)', bygroups(Generic.Deleted, Whitespace)), - (r'(!.*)(\n)', bygroups(Generic.Strong, Whitespace)), - (r'(@.*)(\n)', bygroups(Generic.Subheading, Whitespace)), + (r'(!.*|---)(\n)', bygroups(Generic.Strong, Whitespace)), + (r'((?:< |-).*)(\n)', bygroups(Generic.Deleted, Whitespace)), + (r'((?:> |\+).*)(\n)', bygroups(Generic.Inserted, Whitespace)), + ( + r'(@.*|\d(?:,\d+)?(?:a|c|d)\d+(?:,\d+)?)(\n)', + bygroups(Generic.Subheading, Whitespace), + ), (r'((?:[Ii]ndex|diff).*)(\n)', bygroups(Generic.Heading, Whitespace)), (r'(=.*)(\n)', bygroups(Generic.Heading, Whitespace)), - (r'(.*)(\n)', Whitespace), + (r'(.*)(\n)', bygroups(Text, Whitespace)), ] } diff --git a/tests/snippets/diff/normal.txt b/tests/snippets/diff/normal.txt new file mode 100644 index 00000000..ae3fd5b7 --- /dev/null +++ b/tests/snippets/diff/normal.txt @@ -0,0 +1,38 @@ +---input--- +1,2d0 +< A +< A +4c2 +< C +--- +> F +5a4 +> E + +---tokens--- +'1,2d0' Generic.Subheading +'\n' Text.Whitespace + +'< A' Generic.Deleted +'\n' Text.Whitespace + +'< A' Generic.Deleted +'\n' Text.Whitespace + +'4c2' Generic.Subheading +'\n' Text.Whitespace + +'< C' Generic.Deleted +'\n' Text.Whitespace + +'---' Generic.Strong +'\n' Text.Whitespace + +'> F' Generic.Inserted +'\n' Text.Whitespace + +'5a4' Generic.Subheading +'\n' Text.Whitespace + +'> E' Generic.Inserted +'\n' Text.Whitespace diff --git a/tests/snippets/diff/unified.txt b/tests/snippets/diff/unified.txt new file mode 100644 index 00000000..360086b8 --- /dev/null +++ b/tests/snippets/diff/unified.txt @@ -0,0 +1,44 @@ +---input--- +--- old.txt 2023-01-17 21:02:15.449417575 -0700 ++++ new.txt 2023-01-17 21:02:12.489441682 -0700 +@@ -1,5 +1,4 @@ +-A +-A + B +-C ++F + D ++E + +---tokens--- +'--- old.txt\t2023-01-17 21:02:15.449417575 -0700' Generic.Deleted +'\n' Text.Whitespace + +'+++ new.txt\t2023-01-17 21:02:12.489441682 -0700' Generic.Inserted +'\n' Text.Whitespace + +'@@ -1,5 +1,4 @@' Generic.Subheading +'\n' Text.Whitespace + +'-A' Generic.Deleted +'\n' Text.Whitespace + +'-A' Generic.Deleted +'\n' Text.Whitespace + +' ' Text.Whitespace +'B' Text +'\n' Text.Whitespace + +'-C' Generic.Deleted +'\n' Text.Whitespace + +'+F' Generic.Inserted +'\n' Text.Whitespace + +' ' Text.Whitespace +'D' Text +'\n' Text.Whitespace + +'+E' Generic.Inserted +'\n' Text.Whitespace |