fix(comark): harden auto-close for code spans, math, escapes, and link text#233
Merged
Conversation
…close When auto-closing a partial stream where link text wraps inline code (e.g. `[`foo`), the scanner skipped all markers inside link text and dropped the unclosed backtick, producing `[`foo]` — the bracket closer landed inside the unclosed code span and rendered as literal text. Track backticks opened inside unclosed link text and close the code span before the bracket when odd.
|
@antfubot is attempting to deploy a commit to the NuxtLabs Team on Vercel. A member of the Team first needs to authorize it. |
…lose Inline emphasis markers (* _ ~) inside an inline code span or math region are literal text, not delimiters, and a backslash escapes the following marker. The counting-based inline closer previously counted all of these, corrupting marker parity and emitting stray closers: - asterisks inside a closed code span/math threw off bold/italic parity - an open code span/math got a spurious emphasis closer appended - escaped markers (\*) were counted as delimiters Track code/math literal regions during the single O(n) scan and skip escaped characters. When a line ends inside an open code/math region, close only that region and suppress emphasis closers. Genuine nested emphasis of mixed marker types remains a documented limitation.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
comark
@comark/ansi
@comark/html
@comark/nuxt
@comark/react
@comark/svelte
@comark/vue
commit: |
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.
🔗 Linked issue
❓ Type of change
📚 Description
Hardens
autoCloseMarkdown()against several inline edge cases that mangled partial streaming output. The inline closer scans the last line counting markers (*,_,~,`,$, …); it previously miscounted markers that are actually literal text, which corrupted marker parity and emitted stray closers.1. Inline code spans and math are now literal regions
Emphasis markers inside an inline code span (
`…`) or inline math ($…$) are literal text, not delimiters. They were being counted, throwing off bold/italic parity:When a line ends inside an unclosed code/math region, only that region is closed and emphasis closers are suppressed, so nothing leaks into the span:
2. Escaped markers are no longer counted
A backslash escapes the following marker, so
\*/\_/\`are literal:3. Inline code inside unclosed link text (earlier commit)
A streaming
[`fooskipped all inline markers inside link text, dropping the unclosed backtick and emitting only the bracket closer — landing]inside the code span:Genuinely nested emphasis of mixed marker types (e.g.
**_text) needs CommonMark flanking resolution and remains a documented limitation, tracked byit.todocases (the downstream markdown-it parser does the real resolution). Complete links, attribute scopes, and block math ($$) are unaffected.📝 Checklist
pnpm verifyand it passes. (comark: 1055/1055 + 2 todo, lint + format clean; 2 pre-existingcomark-vuetypecheck errors are unrelated)This PR was created with the help of an agent.