From f2b95c74e8d5d5da25dd56b6574c10f33c7febff Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Thu, 25 Jun 2026 11:11:55 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20html=5Fblock:=20stop=20ea?= =?UTF-8?q?rly=20at=20blank=20lines=20inside=20containers=20for=20non-blan?= =?UTF-8?q?k-line-terminator=20sequences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HTML blocks started with ``). 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 #377. --- markdown_it/rules_block/html_block.py | 2 +- tests/test_port/fixtures/commonmark_extras.md | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/markdown_it/rules_block/html_block.py b/markdown_it/rules_block/html_block.py index 3d43f6ee..fee2a1a0 100644 --- a/markdown_it/rules_block/html_block.py +++ b/markdown_it/rules_block/html_block.py @@ -68,7 +68,7 @@ def html_block(state: StateBlock, startLine: int, endLine: int, silent: bool) -> # Let's roll down till block end. if not html_seq[1].search(lineText): while nextLine < endLine: - if state.sCount[nextLine] < state.blkIndent: + if state.sCount[nextLine] < state.blkIndent and not state.isEmpty(nextLine): break pos = state.bMarks[nextLine] + state.tShift[nextLine] diff --git a/tests/test_port/fixtures/commonmark_extras.md b/tests/test_port/fixtures/commonmark_extras.md index f0b31dbd..0cb8d978 100644 --- a/tests/test_port/fixtures/commonmark_extras.md +++ b/tests/test_port/fixtures/commonmark_extras.md @@ -749,3 +749,27 @@ Issue #204. Combination of blockquotes, list and newlines causes an IndexError . + +Issue #377. HTML comment block inside list item should not end at blank line +. +1. item + + + paragraph +. +
    +
  1. +

    item

    + +

    paragraph

    +
  2. +
+.