Skip to content

Commit e4cefdd

Browse files
sushicwjoshgoebel
andauthored
Fix unified diff hunk header highlight to allow for single-number case (#4228)
* Fix unified diff hunk header highlight to allow for single-number case * update changelog * add test cases * additional test cases * Switch to multiple simpler regexes --------- Co-authored-by: Josh Goebel <[email protected]>
1 parent d864744 commit e4cefdd

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ Core Grammars:
1010
- fix(javascript) correctly highlight 'for await' again [wolfgang42][]
1111
- enh(csp) add missing directives / keywords from MDN (7 more) [Max Liashuk][]
1212
- enh(ada) add new `parallel` keyword, allow `[]` for Ada 2022 [Max Reznik][]
13+
- fix(diff) fix unified diff hunk header regex to allow unpaired numbers [Chris Wilson][]
1314
- enh(php) support single line and hash comments in attributes, constructor and functions [Antoine Musso][]
1415

1516
CONTRIBUTORS
1617

1718
[Josh Marchand]: https://github.com/yHSJ
1819
[Max Liashuk]: https://github.com/probil
1920
[Max Reznik]: https://github.com/reznikmm
21+
[Chris Wilson]: https://github.com/sushicw
2022
[Antoine Musso]: https://github.com/hashar
2123
[Chester Moses]: https://github.com/Chester-Moses-HCL
2224

src/languages/diff.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ export default function(hljs) {
1717
className: 'meta',
1818
relevance: 10,
1919
match: regex.either(
20-
/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,
20+
/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/, // @@ -1,2 +1,2 @@
21+
/^@@ +-\d+ +\+\d+,\d+ +@@/, // @@ -1 +1,2 @@
22+
/^@@ +-\d+,\d+ +\+\d+ +@@/, // @@ -1,2 +1 @@
23+
/^@@ +-\d+ +\+\d+ +@@/, // @@ -1 +1 @@
2124
/^\*\*\* +\d+,\d+ +\*\*\*\*$/,
2225
/^--- +\d+,\d+ +----$/
2326
)

test/markup/diff/git-format-patch.expect.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,26 @@
1212
<span class="hljs-meta">@@ -28,2 +28,2 @@</span>
1313
<span class="hljs-deletion">- removal</span>
1414
<span class="hljs-addition">+ addition</span>
15+
<span class="hljs-comment">diff --git a/file.txt b/file.txt</span>
16+
<span class="hljs-comment">index 8baef1b..24c5735 100644</span>
17+
<span class="hljs-comment">--- a/file.txt</span>
18+
<span class="hljs-comment">+++ b/file.txt</span>
19+
<span class="hljs-meta">@@ -1 +1 @@</span>
20+
<span class="hljs-deletion">-removal</span>
21+
<span class="hljs-addition">+addition</span>
22+
<span class="hljs-comment">diff --git a/file.txt b/file.txt</span>
23+
<span class="hljs-comment">index f9308d8..f39c17d 100644</span>
24+
<span class="hljs-comment">--- a/file.txt</span>
25+
<span class="hljs-comment">+++ b/file.txt</span>
26+
<span class="hljs-meta">@@ -1,2 +1 @@</span>
27+
<span class="hljs-deletion">-removal1</span>
28+
<span class="hljs-deletion">-removal2</span>
29+
<span class="hljs-addition">+addition</span>
30+
<span class="hljs-comment">diff --git a/file.txt b/file.txt</span>
31+
<span class="hljs-comment">index 1037b05..54addbd 100644</span>
32+
<span class="hljs-comment">--- a/file.txt</span>
33+
<span class="hljs-comment">+++ b/file.txt</span>
34+
<span class="hljs-meta">@@ -1 +1,2 @@</span>
35+
<span class="hljs-deletion">-removal</span>
36+
<span class="hljs-addition">+addition1</span>
37+
<span class="hljs-addition">+addition2</span>

test/markup/diff/git-format-patch.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,26 @@ index 123456..789abc 100644
1212
@@ -28,2 +28,2 @@
1313
- removal
1414
+ addition
15+
diff --git a/file.txt b/file.txt
16+
index 8baef1b..24c5735 100644
17+
--- a/file.txt
18+
+++ b/file.txt
19+
@@ -1 +1 @@
20+
-removal
21+
+addition
22+
diff --git a/file.txt b/file.txt
23+
index f9308d8..f39c17d 100644
24+
--- a/file.txt
25+
+++ b/file.txt
26+
@@ -1,2 +1 @@
27+
-removal1
28+
-removal2
29+
+addition
30+
diff --git a/file.txt b/file.txt
31+
index 1037b05..54addbd 100644
32+
--- a/file.txt
33+
+++ b/file.txt
34+
@@ -1 +1,2 @@
35+
-removal
36+
+addition1
37+
+addition2

0 commit comments

Comments
 (0)