Keep a comment inside raw inline HTML in the same paragraph - #1648
Open
wolfgang-aura wants to merge 2 commits into
Open
wolfgang-aura wants to merge 2 commits into
wolfgang-aura wants to merge 2 commits into
Conversation
Member
|
You have a good set of tests here. However, I would like one more added. There should be no change in behavior for this one but I would like to ensure it stays that way. |
Author
|
Added |
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.
Description
Fixes #1643.
A raw HTML comment on its own line inside an inline element was always treated as a block, so this input:
rendered as
<p><span></p>\n<!-- comment -->\n<p></span></p>. This change makes it render as<p><span>\n<!-- comment -->\n</span></p>, which matchesmarkdown.plas described in the issue.HTMLExtractornow keeps a stack of raw inline tags that are open in the current paragraph.handle_commenttreats the comment as inline only when one of those tags is closed later in the same paragraph and the comment has no blank line in it. A blank line in the data clears the stack. Everything else keeps the current block behaviour:<img>;md_in_htmlgets the same two hook calls so both parsers behave the same. Nothing special-cases<picture>.Tests: eight new cases in
tests/test_syntax/blocks/test_html_blocks.py. Themd_in_htmltest class inherits them, so they run under both parsers. The two own-line cases fail without the change, and the other six pin behaviour that must stay as it is. The full suite passes (1114 tests, 52 skipped), and flake8 is clean on the changed files. A changelog entry is under [Unreleased].Not covered: an inline element that contains a block-level element and then a comment, such as
<span>\n<div>x</div>\n<!-- c -->\n</span>, still splits as it does today.AI Assistance Disclosure
The change and tests were written by Claude Code (claude-sonnet-5-5) and reviewed by a second Claude Code run. The edge cases above were compared with the base commit's output, and the tests were run on Windows with Python 3.14.
Checklist