fix: parse EOF backtick fences after paragraphs - #4039
Open
deepakganesh78 wants to merge 2 commits into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@deepakganesh78 is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fixes #4038
Reproduction
On current
master, EOF fenced code blocks are swallowed into the preceding paragraph for both fence characters:CommonMark treats backtick and tilde fences the same for paragraph interruption, and an unclosed fence is closed by EOF. With this change,
foo\n````,foo\n```js,foo\n~~~`, and `foo\n~~~js` all end the paragraph and produce a fenced code block.Root cause
The block fence tokenizer already accepts EOF after an opening fence, but the paragraph/table interruption regexes only recognized a fence when the opening fence line ended with
\n. At EOF, paragraph parsing consumed the fence as literal text before the fence tokenizer could run. The first version of this PR only allowed EOF in the backtick branch; the tilde branch had the same bug.Fix
Allow the paragraph/table interruption checks to match either a newline or EOF after the opening fence line for both backtick and tilde fences. The backtick-specific lookahead is kept so inline code spans are not treated as fences; tildes share the same trailing line/EOF handling.
Compatibility notes
This changes parsing only for fenced code blocks at EOF when they interrupt a paragraph or GFM table row. Newline-terminated fences and inline code span cases such as
a `b` candfoo\n`bar`were verified unchanged. The existing long-tilde ReDoS fixture was updated to the now-correct EOF-fence output while still covering the same large input.Validation
Empirical outputs after rebuild (
npm run build:esbuild):foo\n```` ->foo
\nfoo\n```js-><p>foo</p>\n<pre><code class="language-js">\n</code></pre>\nfoo\n~~~-><p>foo</p>\n<pre><code>\n</code></pre>\nfoo\n~~~js-><p>foo</p>\n<pre><code class="language-js">\n</code></pre>\na \b` c->a
\n`bcfoo\n\bar`->foo\n
\n`barRegression verification:
src/rules.ts,node --test --test-reporter=spec test/run-spec-tests.jsreportedtests 1771,pass 1765,fail 6; bothbacktick_fence_eof_interrupts_paragraphandtilde_fence_eof_interrupts_paragraphfailed (plus the updated long-tilde ReDoS fixture).npm run test:specsreportedtests 1771,pass 1771,fail 0.npm run test:types: passed (exit 0;attwreports the existing ignored CJS-to-ESM warning only).npm run test:lint: passed (exit 0).npm run test:umd: passed (exit 0).npm run test:cjs: passed (exit 0).npm run test:unitreportedtests 190,pass 185,fail 5(exec,stdin,string,input,input file positional,input last file positionalfail withCannot find module 'E:\Work\Code').