web: let emphasis reach across an inline code span - #172
Merged
Conversation
A model answer like "**874 `.md` files** on disk" showed its asterisks on the page. renderInline split the text on backticks first and handed each non-code part to the emphasis pass on its own, so an opening ** and its closing ** never met when a code span sat between them. The emphasis pattern now runs over a copy of the text in which every code span and every link is a run of NULs of the same length, and the match indices slice the original. Code still wins inside itself, so backticks around **text** show the asterisks and emphasise nothing. A link is hidden for the same reason a code span is: an underscore in its URL is not a delimiter. The run between a matched pair is rendered by recursing over it, so a strong or em may now hold a code span or a link, and emphasis inside a link label works as before. Unmatched delimiters stay literal. No HTML string is assembled anywhere. Every node is created with createElement and every string lands as a text node or through textContent, as before. Claude-Session: https://claude.ai/code/session_01PG2vuux5tMsjnZBLWJzMyp
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.
The bug
The browser markdown renderer did not render bold when the bold span contained inline code. An answer like this showed its asterisks on the page:
renderInlinesplit the text on backticks first and handed each non-code part to the emphasis pass on its own, so an opening**and its closing**never met when a code span sat between them.The fix
The emphasis pattern now runs over a copy of the text in which every code span and every link is a run of NULs of the same length, and the match indices slice the original. That is what lets emphasis see across a code span without seeing into it.
**text**show the asterisks and emphasise nothing.<strong>or<em>may now hold a<code class="inline-code">or an<a>. Emphasis inside a link label works as before.createElementand every string lands as a text node or throughtextContent.Only
web/src/markdown.tsandweb/test/markdown.test.tschange. No Rust is touched and nodocs/DECISIONS.mdentry is needed.Tests
Seven new cases in
web/test/markdown.test.ts: bold containing a code span, bold starting with a code span, italic containing a code span, asterisks inside a code span staying literal next to real emphasis, an unmatched**followed by a code span staying literal, a link inside bold still rendering as a link, and an underscore in a link URL not being a delimiter. All existing injection cases pass unchanged.From
web/:npm run check,npm test(366 pass, 0 fail; 27 in the markdown suite),npm run buildall pass.https://claude.ai/code/session_01PG2vuux5tMsjnZBLWJzMyp