Repository navigation
🐛 HTML block start outside a list item closes the list - #442
Open
inchang-ing wants to merge 1 commit into
Open
inchang-ing wants to merge 1 commit into
inchang-ing wants to merge 1 commit into
Conversation
…lebooks#442) 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
Author
|
Hi maintainers, gentle ping on #442 — fix(block): HTML block start outside a list item closes the list. It's a small, self-contained fix with passing tests. Would appreciate a review when you have a moment. Thanks for maintaining executablebooks/markdown-it-py! |
inchang-ing
force-pushed
the
fix/html-block-closes-list
branch
from
October 16, 2026 08:33
597b896 to
df3fc1f
Compare
Author
|
Addressed the pre-commit.ci mypy failure and tidied the PR up:
Verified locally with the same dependency set as 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.CHANGELOG.md: entry under Unreleased, per the contributing guidance inAGENTS.md.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: the issue's input; 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..[testing,linkify]): 1037 passed, 0 failed; pristine master in the same environment: 1032 passed — the delta is exactly the 5 new tests, so zero regressions (CommonMark spec tests included).test_html_block_under_indented_closes_listfail, so the tests do pin the fix.ruff check/ruff formatclean on touched files;mypy --strictclean (the tests buildMarkdownItlocally instead of via a fixture, matching the example pattern inAGENTS.md— the pre-commit mypy environment does not have pytest installed, and an untyped decorator is not allowed under the repo's strict settings).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).