Skip to content

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

Merged
puzrin merged 1 commit into
markdown-it:masterfrom
ATOM00blue:fix/html-block-comment-end
May 22, 2026
Merged

fix: don't end HTML comment blocks on a blank line#1155
puzrin merged 1 commit into
markdown-it:masterfrom
ATOM00blue:fix/html-block-comment-end

Conversation

@ATOM00blue

Copy link
Copy Markdown
Contributor

Problem

An HTML block of types 1-5 (e.g. a <!-- ... --> comment) should continue until its closing sequence (-->), per CommonMark; only block types 6 and 7 end on a blank line. Inside a container such as a list item, a blank line is outdented (sCount 0), so the scanner terminated a comment block early instead of running to -->.

Fix

Detect whether the matched HTML block type actually ends on a blank line (its closing regexp matches the empty string). For types that do not, an outdented blank line is treated as regular block content rather than a terminator, so comment blocks no longer depend on indentation.

Tests

Added regression fixtures for #1144. Full CommonMark conformance suite passes (652/652).

Closes #1144

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 markdown-it#1144.
Copilot AI review requested due to automatic review settings May 21, 2026 02:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes markdown-it’s HTML block parsing so that HTML block types 1–5 (notably <!-- ... --> comments) do not terminate on a blank line inside containers (e.g., list items / blockquotes), aligning behavior with the CommonMark spec and addressing #1144.

Changes:

  • Update html_block scanning logic to treat outdented blank lines as regular content for HTML block types whose closing regex does not match an empty string (types 1–5).
  • Add regression fixtures covering HTML comment blocks spanning blank lines inside a list item and inside a blockquote.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/rules_block/html_block.mjs Adjusts HTML block termination logic so comment blocks don’t end early on outdented blank lines inside containers.
test/fixtures/markdown-it/commonmark_extras.txt Adds regression fixtures for #1144 (list + blockquote cases with blank lines inside HTML comments).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@puzrin

puzrin commented May 21, 2026

Copy link
Copy Markdown
Member

Looks very elegant. I thought the resolution of the problem with comments in HTML blocks would be much more complicated.

The only question is what spec says about multiple comments?

<!-- xxx --> yyy <!-- xxxxxx --> yyy <!--

In single or multiple lines, all inside an HTML block. Does it require determining the proper close exactly or not?

That's not a requirement from my side. Only if you have time. I'm for merging PR in the current state, too, because it solves a real practical problem.

@puzrin puzrin merged commit 68cfb8c into markdown-it:master May 22, 2026
4 of 5 checks passed
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.

HTML comment block incorrectly ended before -->

3 participants