fix: don't end HTML comment blocks on a blank line#1155
Conversation
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.
There was a problem hiding this comment.
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_blockscanning 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.
|
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? 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. |
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 (sCount0), 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