Skip to content

fix(parser): preserve pseudo-tags inside inline code spans - #2904

Merged
jung-thomas merged 1 commit into
DEVfrom
worktree-fix-codespan-pseudotag-escape
Oct 24, 2026
Merged

jung-thomas merged 1 commit into
DEVfrom
worktree-fix-codespan-pseudotag-escape

Conversation

@jung-thomas

Copy link
Copy Markdown
Contributor

Problem

A <MyApp /> typed inside a backtick code span in tutorial source renders on the published page as the literal text &lt;MyApp /&gt; instead of <MyApp />. Reported on the React/JSX tutorials — a tip reads:

Note that `` is using a self-closing syntax…

…and the <MyApp /> showed up as &lt;MyApp /&gt;.

Root cause

sanitizeLine in scripts/parsers/sanitize-html.ts runs on raw markdown, line-by-line, and pseudo-tag-escapes any unknown tag-like token to &lt;…&gt; — it can't tell the token is inside an inline code span (between backticks). Goldmark then renders the span as <code> and HTML-escapes the content a second time, so < → &lt; → the visible literal &lt;.

The author markdown was correct; this was always a parser bug.

Fix

Stash inline code spans (`...` and ... ) before pseudo-tag/sanitize processing and restore them verbatim at the end — same pattern the file already uses for autolinks. Stashing runs before autolink extraction so a <url> inside a span stays literal. Pseudo-tags outside code spans are still escaped exactly as before.

Testing

  • 3 new unit tests (inline span, mixed line with span + bare pseudo-tag, double-backtick span) — RED before, GREEN after
  • Full sanitize-html.test.ts: 66/66 pass
  • Corpus/parser suites: 59/59 pass
  • Catalog smoke (sanitize-html-catalog-smoke.ts, classifier taught the matching code-span exception): 0 regressions across 1498 tutorials, exit 0
  • Verified the exact reported tip line round-trips unchanged through stripDangerousHtml

A `<MyApp />` inside a backtick code span was being double-escaped to
the literal text `&lt;MyApp /&gt;` on the rendered page.

Root cause: sanitizeLine (stripDangerousHtml) runs on raw markdown
line-by-line and pseudo-tag-escapes any unknown tag-like token to
`&lt;...&gt;` — including tokens inside inline code spans. Goldmark then
renders the backtick span as <code> and HTML-escapes the `&` a second
time, so `<` becomes `&lt;` becomes the visible literal `&lt;`.

Fix: stash inline code spans (`...`, ``...``) before pseudo-tag/sanitize
processing and restore them verbatim at the end, mirroring the existing
autolink-stash pattern. Stashing happens before autolink extraction so a
`<url>` inside a span stays literal. Pseudo-tags OUTSIDE code spans are
still escaped as before.

- 3 new unit tests (inline span, mixed line, double-backtick span)
- catalog smoke classifier taught the same code-span exception
- verified 0 regressions across 1498 corpus tutorials

Fixes the JSX tip rendering reported on the React tutorials.
@jung-thomas
jung-thomas merged commit fa4beb2 into DEV Oct 24, 2026
3 of 4 checks passed
@jung-thomas
jung-thomas deleted the worktree-fix-codespan-pseudotag-escape branch October 24, 2026 05:12
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