🐛 FIX: html_block: blank lines inside containers prematurely terminate non-blank-line-terminator sequences#406
Open
gaoflow wants to merge 1 commit into
Conversation
…n-blank-line-terminator sequences HTML blocks started with `<!--`, `<?`, `<!A`, `<![CDATA[`, or `<script>`/`<pre>`/`<style>`/`<textarea>` (CommonMark types 1–5) have specific end conditions (e.g. `-->`). Per the CommonMark spec §4.6, these blocks continue until the matching end tag is found, or until the last line of the document / container block — blank lines inside them do NOT terminate them. When such a block appeared inside a container (e.g. a list item) a blank line within the comment caused `state.sCount[nextLine] < state.blkIndent` to fire and break out of the scan loop early. Blank lines always have `sCount = 0`, so any positive `blkIndent` would trigger the break even though the blank line was still part of the containing list item. Fix: skip the `sCount < blkIndent` guard for blank lines (`state.isEmpty(nextLine)`). Blank lines that belong to a blank-line-terminator sequence (types 6–7, end condition `^$`) still terminate correctly because an empty `lineText` matches `^$` via the end-condition check. Fixes executablebooks#377.
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
HTML blocks started with
<!--,<?,<!A,<![CDATA[, or<script>/<pre>/<style>/<textarea>(CommonMark types 1–5) have specific end conditions (-->,?>,>,]]>, closing tags). Per CommonMark spec §4.6, these blocks continue until the matching end tag is found, or the last line of the document/container — blank lines inside them do not terminate them.When such a block appeared inside a container (e.g. a list item), a blank line within the comment caused early termination. The scan loop in
html_blockchecksstate.sCount[nextLine] < state.blkIndentto detect container boundaries, but blank lines always havesCount = 0, so any positiveblkIndent(set by the list rule) incorrectly fired the guard.Reproduction (from #377):
Before this fix,
-->was escaped as-->inside a paragraph (comment prematurely closed at the blank line).Fix
One-character addition: skip the
sCount < blkIndentguard when the line is blank (state.isEmpty(nextLine)). Blank lines in sequences 6–7 (end condition^$) still terminate correctly because an emptylineTextmatches^$through the existing end-condition check.Test
New fixture in
commonmark_extras.mdcovering the exact case from #377.This pull request was prepared with the assistance of AI, under my direction and review.