Repository navigation
fix(parser): preserve pseudo-tags inside inline code spans - #2904
Merged
Merged
Conversation
A `<MyApp />` inside a backtick code span was being double-escaped to the literal text `<MyApp />` 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 `<...>` — including tokens inside inline code spans. Goldmark then renders the backtick span as <code> and HTML-escapes the `&` a second time, so `<` becomes `<` becomes the visible literal `<`. 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.
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.
Problem
A
<MyApp />typed inside a backtick code span in tutorial source renders on the published page as the literal text<MyApp />instead of<MyApp />. Reported on the React/JSX tutorials — a tip reads:…and the
<MyApp />showed up as<MyApp />.Root cause
sanitizeLineinscripts/parsers/sanitize-html.tsruns on raw markdown, line-by-line, and pseudo-tag-escapes any unknown tag-like token to<…>— 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<→<→ the visible literal<.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
sanitize-html.test.ts: 66/66 passsanitize-html-catalog-smoke.ts, classifier taught the matching code-span exception): 0 regressions across 1498 tutorials, exit 0stripDangerousHtml