Skip to content

Fix unified diff hunk header highlight to allow for single-number case #4228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -10,13 +10,15 @@ Core Grammars:
- fix(javascript) correctly highlight 'for await' again [wolfgang42][]
- enh(csp) add missing directives / keywords from MDN (7 more) [Max Liashuk][]
- enh(ada) add new `parallel` keyword, allow `[]` for Ada 2022 [Max Reznik][]
- fix(diff) fix unified diff hunk header regex to allow unpaired numbers [Chris Wilson][]
- enh(php) support single line and hash comments in attributes, constructor and functions [Antoine Musso][]

CONTRIBUTORS

[Josh Marchand]: https://github.com/yHSJ
[Max Liashuk]: https://github.com/probil
[Max Reznik]: https://github.com/reznikmm
[Chris Wilson]: https://github.com/sushicw
[Antoine Musso]: https://github.com/hashar
[Chester Moses]: https://github.com/Chester-Moses-HCL

5 changes: 4 additions & 1 deletion src/languages/diff.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,10 @@ export default function(hljs) {
className: 'meta',
relevance: 10,
match: regex.either(
/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,
/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/, // @@ -1,2 +1,2 @@
/^@@ +-\d+ +\+\d+,\d+ +@@/, // @@ -1 +1,2 @@
/^@@ +-\d+,\d+ +\+\d+ +@@/, // @@ -1,2 +1 @@
/^@@ +-\d+ +\+\d+ +@@/, // @@ -1 +1 @@
/^\*\*\* +\d+,\d+ +\*\*\*\*$/,
/^--- +\d+,\d+ +----$/
)
23 changes: 23 additions & 0 deletions test/markup/diff/git-format-patch.expect.txt
Original file line number Diff line number Diff line change
@@ -12,3 +12,26 @@
<span class="hljs-meta">@@ -28,2 +28,2 @@</span>
<span class="hljs-deletion">- removal</span>
<span class="hljs-addition">+ addition</span>
<span class="hljs-comment">diff --git a/file.txt b/file.txt</span>
<span class="hljs-comment">index 8baef1b..24c5735 100644</span>
<span class="hljs-comment">--- a/file.txt</span>
<span class="hljs-comment">+++ b/file.txt</span>
<span class="hljs-meta">@@ -1 +1 @@</span>
<span class="hljs-deletion">-removal</span>
<span class="hljs-addition">+addition</span>
<span class="hljs-comment">diff --git a/file.txt b/file.txt</span>
<span class="hljs-comment">index f9308d8..f39c17d 100644</span>
<span class="hljs-comment">--- a/file.txt</span>
<span class="hljs-comment">+++ b/file.txt</span>
<span class="hljs-meta">@@ -1,2 +1 @@</span>
<span class="hljs-deletion">-removal1</span>
<span class="hljs-deletion">-removal2</span>
<span class="hljs-addition">+addition</span>
<span class="hljs-comment">diff --git a/file.txt b/file.txt</span>
<span class="hljs-comment">index 1037b05..54addbd 100644</span>
<span class="hljs-comment">--- a/file.txt</span>
<span class="hljs-comment">+++ b/file.txt</span>
<span class="hljs-meta">@@ -1 +1,2 @@</span>
<span class="hljs-deletion">-removal</span>
<span class="hljs-addition">+addition1</span>
<span class="hljs-addition">+addition2</span>
23 changes: 23 additions & 0 deletions test/markup/diff/git-format-patch.txt
Original file line number Diff line number Diff line change
@@ -12,3 +12,26 @@ index 123456..789abc 100644
@@ -28,2 +28,2 @@
- removal
+ addition
diff --git a/file.txt b/file.txt
index 8baef1b..24c5735 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1 @@
-removal
+addition
diff --git a/file.txt b/file.txt
index f9308d8..f39c17d 100644
--- a/file.txt
+++ b/file.txt
@@ -1,2 +1 @@
-removal1
-removal2
+addition
diff --git a/file.txt b/file.txt
index 1037b05..54addbd 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1,2 @@
-removal
+addition1
+addition2