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

Conversation

sushicw
Copy link
Contributor

@sushicw sushicw commented Mar 19, 2025

Resolves #4227

Changes

Update the regex for matching a unified hunk header to allow for single numbers as well as comma-paired numbers.

From https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html, emphasis mine:

If a hunk contains just one line, only its start line number appears. Otherwise its line numbers look like ‘start,count’. An empty hunk is considered to start at the line that follows the hunk.

If a hunk and its context contain two or more lines, its line numbers look like ‘start,count’. Otherwise only its end line number appears. An empty hunk is considered to end at the line that precedes the hunk.

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

@sushicw
Copy link
Contributor Author

sushicw commented Apr 2, 2025

Hi @joshgoebel, can you please take another look and approve if this is ready? Thanks!

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

6 files changed

Total change +7 B

View Changes
file base pr diff
es/languages/diff.min.js 373 B 382 B +9 B
es/languages/javascript.min.js 2.74 KB 2.74 KB -2 B
es/languages/typescript.min.js 3.21 KB 3.21 KB -3 B
languages/diff.min.js 376 B 385 B +9 B
languages/javascript.min.js 2.75 KB 2.74 KB -3 B
languages/typescript.min.js 3.22 KB 3.21 KB -3 B

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

7 files changed

Total change +4 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB +1 B
es/highlight.min.js 8.19 KB 8.19 KB +1 B
es/languages/diff.min.js 373 B 382 B +9 B
es/languages/php.min.js 2.66 KB 2.65 KB -9 B
highlight.min.js 8.23 KB 8.23 KB +1 B
languages/diff.min.js 376 B 385 B +9 B
languages/php.min.js 2.66 KB 2.66 KB -8 B

Copy link

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +24 B

View Changes
file base pr diff
es/core.min.js 8.19 KB 8.19 KB +2 B
es/highlight.min.js 8.19 KB 8.19 KB +2 B
es/languages/diff.min.js 373 B 382 B +9 B
highlight.min.js 8.23 KB 8.23 KB +2 B
languages/diff.min.js 376 B 385 B +9 B

@joshgoebel joshgoebel merged commit e4cefdd into highlightjs:main Apr 23, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(diff) Won't highlight hunk headers with a single number instead of a number pair
3 participants