Skip to content
13 changes: 12 additions & 1 deletion markdown_it/rules_block/html_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@ def html_block(state: StateBlock, startLine: int, endLine: int, silent: bool) ->

nextLine = startLine + 1

# Block types 6 and 7 (the only ones whose end condition is a blank line)
# have `^$` as their closing regexp. For all other types (1-5, e.g.
# `<!--` comments), a blank line is regular content and must not terminate
# the block - it ends only when its closing sequence is found.
endsOnBlankLine = bool(html_seq[1].search(""))

# If we are here - we detected HTML block.
# Let's roll down till block end.
if not html_seq[1].search(lineText):
while nextLine < endLine:
if state.sCount[nextLine] < state.blkIndent:
# An outdented blank line shouldn't end a block that doesn't end on a
# blank line (e.g. a `<!--` comment inside a list item). Such blocks
# must continue until their closing sequence regardless of indent.
if state.sCount[nextLine] < state.blkIndent and (
endsOnBlankLine or not state.isEmpty(nextLine)
):
break

pos = state.bMarks[nextLine] + state.tShift[nextLine]
Expand Down
43 changes: 43 additions & 0 deletions tests/test_port/fixtures/commonmark_extras.md
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,46 @@ A no-break space is not a space, so a code span holding one between single space
.
<p><code> </code></p>
.

Issue #1144. Comment HTML block (type 2) must not end on a blank line inside a list
.
1. item

<!--
a

b
-->
c
.
<ol>
<li>
<p>item</p>
<!--
a

b
-->
<p>c</p>
</li>
</ol>
.

Issue #1144. Comment HTML block spanning a blank line inside a blockquote
.
> <!--
> a
>
> b
> -->
> c
.
<blockquote>
<!--
a

b
-->
<p>c</p>
</blockquote>
.
32 changes: 32 additions & 0 deletions tests/test_port/fixtures/issue-fixes.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,35 @@ Image alt keeps escapes, entities and code span text together
.
<p><img src="/u" alt="a * c&lt;d &amp; e" /></p>
.

#377 comment HTML block in a list item still ends at the next item after a blank line
.
- <!--

- b
.
<ul>
<li>
<!--

</li>
<li>
<p>b</p>
</li>
</ul>
.

#377 comment HTML block in a list item still ends at an outdented non-blank line
.
- <!--
foo
-->
.
<ul>
<li>
<!--
</li>
</ul>
<p>foo
--&gt;</p>
.
Loading