fix(block): HTML block start outside a list item closes the list - #442
Open
inchang-ing wants to merge 2 commits into
Open
inchang-ing wants to merge 2 commits into
inchang-ing wants to merge 2 commits into
Conversation
A line that starts an HTML block on an under-indented line was consumed as a lazy continuation of the item's paragraph, because the type-7 sequence is flagged as unable to terminate a paragraph. cmark and commonmark.js instead end the list: the line cannot be item content, and a block start is not a lazy continuation. End the paragraph when the next line starts an HTML block while being under-indented for the current container, so the list closes and the line is offered to the outer containers. At the same container level a type-7 sequence still cannot interrupt the paragraph, and plain text remains a lazy continuation, so the behaviors all implementations agree on are unchanged. Fixes executablebooks#434
for more information, see https://pre-commit.ci
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #434
Problem
A line that starts an HTML block (any type) on a line under-indented for the list item's content was consumed as a lazy continuation of the item's paragraph:
rendered as
<li>a\n<br></li>in markdown-it-py (and in the JS original), while cmark and commonmark.js close the list and open the HTML block at the outer level — because such a line can neither be item content nor a lazy continuation of it (it starts a new block). Flipping the type-7 "can terminate paragraph" flag is not a fix: it would let<br>interrupt a top-level paragraph, where all implementations agree it must not.Change
html_block.py: newhtml_block_starts(state, line)helper — detects whether a line begins an HTML block of any type (same sequence table as the rule).paragraph.py: while scanning continuation lines, end the paragraph when the next line starts an HTML block and is under-indented for the current container (sCount < blkIndent). The list rule then sees the line, finds no item marker, and closes the list, so the line is offered to the outer containers — reproducing cmark's container walk. At the same container level a type-7 sequence still does not interrupt the paragraph (the terminator rules are unchanged), and plain text at outer indentation remains a lazy continuation.Verification
<h2>Opts</h2><ul><li>a</li></ul><br>\n## Next(the type-7 block swallows## Nextup to a blank line, as cmark does).tests/test_html_block_list.py: HTML block at the item's content indent stays a lazy continuation; a top-level paragraph still continues through<br>; plain text at outer indentation is still a lazy continuation; a type-6 block (<div>) still closes the list as before.git stashdiffed — zero regressions; 958+ passed).ruff checkandruff formatclean on touched files.Note
The JS markdown-it behaves the same way as this library currently does, so this change intentionally diverges from upstream JS toward the cmark/commonmark.js behavior documented in the issue; happy to align on whatever the maintainers decide.
Disclosure
This PR was prepared with AI assistance (ZCode/GLM, orchestrated via WorkBuddy).