fix: patch hljs markdown grammar and re-enable for diff view#388
Merged
tomasz-tomczyk merged 2 commits intomainfrom Apr 29, 2026
Merged
fix: patch hljs markdown grammar and re-enable for diff view#388tomasz-tomczyk merged 2 commits intomainfrom
tomasz-tomczyk merged 2 commits intomainfrom
Conversation
Restores markdown syntax highlighting (PR #283 had disabled it because hljs's stock grammar mangled snake_case identifiers, bare ***/---/___ lines, code spans containing emphasis chars, and treated YAML frontmatter delimiters as setext heading underlines). Adds frontend/highlight-markdown-patch.js — a vendored grammar override re-registered after the upstream language file loads. Fixes: - hljs#4279: intraword underscores no longer trigger italic/bold (snake_case, flutter_eval, ⛔ stay plain) - hljs#3719: bare ***/---/___ lines render as horizontal rule, not bold - code spans (\`*foo*\`) consumed before emphasis matchers — no italic bleed - setext headings reject upper lines that are list items / blockquotes / ATX headers / ordered lists / indented code (per CommonMark §4.3), fixing YAML frontmatter false-positives Wired through copy-deps.js to append after languages bundle. Markdown files are now also pre-highlighted in diff view (preHighlightFile and the call-site gate in app.js). Removes the markdown skip guard from the markdown-it highlight callbacks. frontend/test-markdown-patch.mjs runs 30 vm-sandboxed assertions against the bundled grammar. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #388 +/- ##
==========================================
+ Coverage 66.58% 66.59% +0.01%
==========================================
Files 19 19
Lines 8176 8176
==========================================
+ Hits 5444 5445 +1
+ Misses 2310 2309 -1
Partials 422 422
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
5 tasks
axe-core flagged hljs-quote (#22863a) on .addition (#dafbe1) at 4.15:1 contrast — fails WCAG AA (needs 4.5:1). Same color is shared with hljs-name, hljs-selector-pseudo, hljs-selector-tag. Darken all four to fg-default (#1f2328) when nested inside .addition rows in light theme. Mirrors the existing .diff-word-del + hljs-* override pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tomasz-tomczyk
added a commit
to tomasz-tomczyk/crit-web
that referenced
this pull request
Apr 29, 2026
Mirrors tomasz-tomczyk/crit fix — hljs-quote/name/selector-pseudo/ selector-tag (#22863a) on .addition (#dafbe1) fails WCAG AA at 4.15:1. Darken to fg-default (#1f2328) when nested inside .addition rows in light theme. See also: tomasz-tomczyk/crit#388 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tomasz-tomczyk
added a commit
to tomasz-tomczyk/crit-web
that referenced
this pull request
Apr 29, 2026
* fix: patch hljs markdown grammar and re-enable for fenced blocks Ports the hljs markdown grammar fix from tomasz-tomczyk/crit#388 to keep the review page in parity. Hosted reviews now syntax-highlight nested ```markdown fences without the cascading visual bugs that caused PR #283 (in crit) to disable markdown highlighting. Adds assets/js/highlight-markdown-patch.js — exports registerMarkdownPatch(hljs) which re-registers the markdown language with four fixes: - hljs#4279: intraword underscores no longer trigger italic/bold - hljs#3719: bare ***/---/___ lines render as horizontal rule, not bold - code spans consumed before emphasis matchers (no italic bleed) - setext headings reject upper lines that aren't paragraphs (per CommonMark §4.3) — fixes YAML frontmatter false-positives The patch is registered at the top of document-renderer.js, immediately after `import hljs from "highlight.js"` and before any hljs.highlight() call. esbuild bundles document-renderer.js as a chunk only loaded on /r/:token, so the patch is applied exactly once per review-page mount. Also removes the `lang === 'markdown'` skip guard from the markdown-it highlight() callback, mirroring the same change in crit/. assets/test-markdown-patch.mjs runs 30 vm-sandboxed assertions covering all four bug classes plus regressions. Run with `node assets/test-markdown-patch.mjs`. See also: tomasz-tomczyk/crit#388 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: AA contrast for green hljs groups on addition rows in light theme Mirrors tomasz-tomczyk/crit fix — hljs-quote/name/selector-pseudo/ selector-tag (#22863a) on .addition (#dafbe1) fails WCAG AA at 4.15:1. Darken to fg-default (#1f2328) when nested inside .addition rows in light theme. See also: tomasz-tomczyk/crit#388 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tomasz-tomczyk
added a commit
that referenced
this pull request
Apr 29, 2026
* fix: patch hljs markdown grammar and re-enable for diff view Restores markdown syntax highlighting (PR #283 had disabled it because hljs's stock grammar mangled snake_case identifiers, bare ***/---/___ lines, code spans containing emphasis chars, and treated YAML frontmatter delimiters as setext heading underlines). Adds frontend/highlight-markdown-patch.js — a vendored grammar override re-registered after the upstream language file loads. Fixes: - hljs#4279: intraword underscores no longer trigger italic/bold (snake_case, flutter_eval, ⛔ stay plain) - hljs#3719: bare ***/---/___ lines render as horizontal rule, not bold - code spans (\`*foo*\`) consumed before emphasis matchers — no italic bleed - setext headings reject upper lines that are list items / blockquotes / ATX headers / ordered lists / indented code (per CommonMark §4.3), fixing YAML frontmatter false-positives Wired through copy-deps.js to append after languages bundle. Markdown files are now also pre-highlighted in diff view (preHighlightFile and the call-site gate in app.js). Removes the markdown skip guard from the markdown-it highlight callbacks. frontend/test-markdown-patch.mjs runs 30 vm-sandboxed assertions against the bundled grammar. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix: AA contrast for green hljs groups on addition rows in light theme axe-core flagged hljs-quote (#22863a) on .addition (#dafbe1) at 4.15:1 contrast — fails WCAG AA (needs 4.5:1). Same color is shared with hljs-name, hljs-selector-pseudo, hljs-selector-tag. Darken all four to fg-default (#1f2328) when nested inside .addition rows in light theme. Mirrors the existing .diff-word-del + hljs-* override pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: Test <test@test.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restores markdown syntax highlighting (#375). PR #283 disabled it because hljs's stock grammar produced cascading visual bugs on common markdown content. Rather than ship without the feature, vendor a patched grammar that overrides the upstream registration after load.
frontend/highlight-markdown-patch.jsre-registersmarkdownwith four fixes:snake_case,flutter_eval,:no_entry:,_idstay plain). Lookbehind/lookahead enforce non-alphanumeric flanks. Asterisk variants unchanged (CommonMark allows intraword*).***/---/___lines render as horizontal rule, not bold. Tightened to full-line match; reordered before BOLD incontains[].CODEahead ofBOLD/ITALICso backtick spans are consumed first. Tightened asterisk patterns to require same-line closer + lookbehind so**/*.go(no closing**) doesn't open a runaway span.---and list-item-followed-by----no longer match setext heading. Per CommonMark §4.3, setext heading text must be a paragraph (not list/blockquote/ATX/ordered-list/indented code). Tightened the upper-line lookahead.Wired into the bundle via
copy-deps.js(appended after upstream languages so it overrides). Markdown files are also now pre-highlighted in diff view (extends the gate atapp.js:410and:750);buildCodeLineBlocksstays gated tocode-only. Thelang === 'markdown'skip guard in the markdown-it highlight callback is removed.frontend/test-markdown-patch.mjsruns 30 vm-sandboxed assertions covering all four bug classes plus regression checks (**bold**,*italic*,***bold-italic***, ATX headings, legitimate setext, code spans). Run withnode frontend/test-markdown-patch.mjs.Review
tomasz-tomczyk/crit-webbranchfix/hljs-markdown-patchesTest plan
make test(go test -race -count=1 ./...) — passingnode frontend/test-markdown-patch.mjs— 30/30 passingmake test-diffrendered the screenshot fixture (nested\``markdown` fence, snake_case, YAML frontmatter delimiters) cleanlyNotes
@highlightjs/cdn-assetsbump silently changes the upstream grammar, the patch may need re-syncing. The smoke test catches that — consider wiring it intoupdate-depsor CI later.🤖 Generated with Claude Code