Skip to content

fix: skip hljs highlighting for markdown code fences#283

Merged
tomasz-tomczyk merged 2 commits intomainfrom
fix/markdown-fence-highlighting
Apr 16, 2026
Merged

fix: skip hljs highlighting for markdown code fences#283
tomasz-tomczyk merged 2 commits intomainfrom
fix/markdown-fence-highlighting

Conversation

@tomasz-tomczyk
Copy link
Copy Markdown
Owner

Summary

  • Skip hljs syntax highlighting for markdown/md code fences — the markdown grammar applies bold headings, italic emphasis, and colored code spans, making markdown-within-markdown fences look half-rendered instead of plain source
  • Add Code Standards section (with ```markdown fence) to test-diff fixtures so make test-diff exercises this scenario with deletion markers interrupting the code block

Test plan

  • Run make test-diff, scroll to Code Standards section — markdown fence should render as plain monospace (no bold headings, no italic *text*)
  • Verify Go/JS/Elixir code fences on the word-diff instance still have syntax highlighting
  • go test ./... passes

🤖 Generated with Claude Code

tomasz-tomczyk and others added 2 commits April 16, 2026 16:30
…ting

Adds a section with italic text, headings, bullet lists, and inline code
to the v1 fixture. This section is absent in v2, producing a pure deletion
marker in the document view — replicating the formatting interruption
scenario from the original bug report.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
hljs's markdown grammar applies bold to headings (hljs-section), italic
to emphasis (hljs-emphasis), and colored spans to backtick code — making
markdown-within-markdown fences look half-rendered rather than showing
plain source. Skip hljs for markdown/md fences so the content falls
through to escapeHtml and renders as uniform monospace text. Other
languages (Go, JS, Elixir, etc.) keep their syntax highlighting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@tomasz-tomczyk tomasz-tomczyk merged commit 77cfa5e into main Apr 16, 2026
4 checks passed
@tomasz-tomczyk tomasz-tomczyk deleted the fix/markdown-fence-highlighting branch April 16, 2026 15:46
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>
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>
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