Skip to content

🐛 FIX: html_block: blank lines inside containers prematurely terminate non-blank-line-terminator sequences#406

Open
gaoflow wants to merge 1 commit into
executablebooks:masterfrom
gaoflow:fix/html-block-blank-line-in-container
Open

🐛 FIX: html_block: blank lines inside containers prematurely terminate non-blank-line-terminator sequences#406
gaoflow wants to merge 1 commit into
executablebooks:masterfrom
gaoflow:fix/html-block-blank-line-in-container

Conversation

@gaoflow

@gaoflow gaoflow commented Jun 25, 2026

Copy link
Copy Markdown

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_block checks state.sCount[nextLine] < state.blkIndent to detect container boundaries, but blank lines always have sCount = 0, so any positive blkIndent (set by the list rule) incorrectly fired the guard.

Reproduction (from #377):

from markdown_it import MarkdownIt
md = MarkdownIt()
text = '''1. item

    <!--
    The following code block specifies the full path.

    [1]: <https://example.com>
    -->
    paragraph
'''
print(md.render(text))

Before this fix, --> was escaped as --&gt; inside a paragraph (comment prematurely closed at the blank line).

Fix

One-character addition: skip the sCount < blkIndent guard when the line is blank (state.isEmpty(nextLine)). Blank lines in sequences 6–7 (end condition ^$) still terminate correctly because an empty lineText matches ^$ through the existing end-condition check.

Test

New fixture in commonmark_extras.md covering the exact case from #377.

This pull request was prepared with the assistance of AI, under my direction and review.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant