🐛 FIX: html_block: blank lines inside containers prematurely terminate non-blank-line-terminator sequences - #406
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.
|
Thanks @binggao1230, and apologies for the slow response. I agree the fix is right against the CommonMark spec: a blank line inside a list item does not end the container, so a type 1–5 HTML block should continue to its real end condition, and the reference implementation renders the #377 example as a comment. The blocker is that this port deliberately mirrors the JavaScript markdown-it, and markdown-it 14.1.1 produces byte-identical output to markdown-it-py for this input (with So I would rather not merge this ahead of upstream. The change is a one-liner, and your fixture translates directly, so would you be willing to open the equivalent pull request against markdown-it/markdown-it, referencing #1144? As soon as it lands there we will port it here, crediting you. I will leave this PR open in the meantime so it is not lost. |
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.