Browse Source

fix: don't end HTML comment blocks on a blank line (#1155)

HTML blocks of types 1-5 (e.g. `<!--` comments) must continue until
their closing sequence (`-->` for comments), per CommonMark. Only
types 6 and 7 end on a blank line.

The block scanner broke out of the continuation loop whenever a line
was outdented below the current block indent. Inside a container such
as a list item, a blank line is outdented (its sCount is 0), so a
comment block was terminated early instead of running to `-->`.

Skip that break for outdented blank lines unless the block type
actually ends on a blank line, so comment blocks no longer depend on
indentation. Adds regression fixtures for issue #1144.

Co-authored-by: ATOM00blue <219721791+ATOM00blue@users.noreply.github.com>
pull/1163/head
wheelman 5 months ago
committed by GitHub
parent
commit
68cfb8c079
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 13
      lib/rules_block/html_block.mjs
  2. 43
      test/fixtures/markdown-it/commonmark_extras.txt

13
lib/rules_block/html_block.mjs

@ -42,11 +42,22 @@ export default function html_block (state, startLine, endLine, silent) {
let 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.
const endsOnBlankLine = HTML_SEQUENCES[i][1].test('')
// If we are here - we detected HTML block.
// Let's roll down till block end.
if (!HTML_SEQUENCES[i][1].test(lineText)) {
for (; nextLine < endLine; nextLine++) {
if (state.sCount[nextLine] < state.blkIndent) { break }
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 (endsOnBlankLine || !state.isEmpty(nextLine)) { break }
}
pos = state.bMarks[nextLine] + state.tShift[nextLine]
max = state.eMarks[nextLine]

43
test/fixtures/markdown-it/commonmark_extras.txt

@ -791,3 +791,46 @@ a*a𐬼*a
<p>a*𐬼a*a</p>
<p>a*a𐬼*a</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>
.

Loading…
Cancel
Save