Lengthen the pre code fence so backtick runs can't close it early#271
Open
chuenchen309 wants to merge 1 commit into
Open
Lengthen the pre code fence so backtick runs can't close it early#271chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
`convert_pre` emitted a fixed three-backtick fence, so a `<pre>` whose content contains a ``` run (or longer) produced an ambiguous fenced block that reparses to different HTML: `<pre>foo\n```\nbar</pre>` closed the fence at the inner ```, splitting one code block into a code block, a paragraph, and an empty code block. Compute the fence from the longest backtick run in the content (at least three, matching the previous default), the same mechanism `convert_code` already uses for inline code. Per CommonMark section 4.5 the closing fence must have at least as many backticks as the opening.
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.
convert_preemits a fixed three-backtick fence, so a<pre>whose content contains a ``` run (or longer) produces an ambiguous fenced code block:That reparses (via any CommonMark parser) to three elements — a
foocode block, abarparagraph, and an empty code block — because the inner ``` closes the fence early. Per CommonMark §4.5, a closing fence must have at least as many backticks as the opening, so a 3-backtick fence can't wrap content that contains a 3-backtick line.convert_codealready handles this for inline code (it counts the longest backtick run and uses one more);convert_predidn't.Fix: compute the fence length from the longest backtick run in the content, at least three (keeping the previous default when there are no backticks), reusing the existing
re_backtick_runspattern.Now
<pre>foo\n```\nbar</pre>produces a 4-backtick fence and reparses back to a single equivalent code block.Verification (re-runnable from the diff): added
test_pre_backticks(content with, a bare,a````b, and plain text) — it fails on the current tree and passes with the fix;tests/→ 84 passed.Disclosure: This PR was authored by an AI coding agent (Claude Code) running on this account: the AI found the bug, ran the repro, wrote the test, and wrote this description. The human account holder reviews every change and is accountable for it. The verification above is real and re-runnable from the diff. If this isn't the kind of contribution you want, say so and I'll close it.