Skip to content

fix: patch hljs markdown grammar and re-enable for fenced blocks#139

Merged
tomasz-tomczyk merged 2 commits intomainfrom
fix/hljs-markdown-patches
Apr 29, 2026
Merged

fix: patch hljs markdown grammar and re-enable for fenced blocks#139
tomasz-tomczyk merged 2 commits intomainfrom
fix/hljs-markdown-patches

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

Ports the hljs markdown grammar fix from tomasz-tomczyk/crit#388 so hosted reviews stay in parity with the local CLI. The review page now syntax-highlights nested ```markdown fences cleanly instead of producing cascading visual bugs (snake_case italicized, bold bleed across code spans, YAML frontmatter delimiters parsed as setext headings).

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
  • Italic bleed across code spans fixed by reordering CODE before BOLD/ITALIC + tighter same-line closer requirements
  • Setext heading false-positives fixed (per CommonMark §4.3 the upper line must be a paragraph)

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.

assets/test-markdown-patch.mjs runs 30 vm-sandboxed assertions covering all four bug classes plus regression checks.

Review

Test plan

  • node assets/test-markdown-patch.mjs — 30/30 passing
  • mix precommit — 471 tests, 0 failures (compile, format, sobelow, deps.audit, test all green)
  • mix assets.build — succeeded

Notes

  • ESM-shaped patch (registerMarkdownPatch(hljs)) instead of crit/'s IIFE since crit-web imports highlight.js from npm via esbuild rather than concatenating CDN bundles.
  • No version bumps. highlight.js ^11.11.1 aligned with crit/'s @highlightjs/cdn-assets ^11.11.1.

See also: tomasz-tomczyk/crit#388

🤖 Generated with Claude Code

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>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.21%. Comparing base (39d5ae9) to head (01f3cf6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #139   +/-   ##
=======================================
  Coverage   77.21%   77.21%           
=======================================
  Files          52       52           
  Lines        1567     1567           
=======================================
  Hits         1210     1210           
  Misses        357      357           
Flag Coverage Δ
unit 77.21% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 tomasz-tomczyk merged commit cc5250d into main Apr 29, 2026
4 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix/hljs-markdown-patches branch April 29, 2026 10:26
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.

1 participant