Repository navigation
Fix HTML blocks nested in indented blocks (#1096) - #1688
Open
inchang-ing wants to merge 3 commits into
Open
inchang-ing wants to merge 3 commits into
inchang-ing wants to merge 3 commits into
Conversation
The HTML preprocessor can only extract a raw block that starts at the beginning of a line. Within a container (a list item, an admonition, etc.) the block is indented, which cannot be told apart from an indented code block, so it was left as text. The block parser then treated it as inline HTML and split it at any blank lines. Once the container has removed its indentation, a block that starts with a block level tag can only be a raw block. A new `RawHtmlBlockProcessor` extracts it there, using the same extractor as the preprocessor (or the `md_in_html` extractor when that extension is enabled). Containers pass their content on a block at a time, so a raw block with blank lines in it is collected across calls, keyed by the container, until it is closed. `RawHtmlFlushTreeprocessor` finishes anything still open when the document has been parsed. The preprocessor is not changed, so extensions that work on the text of the document before it is parsed see exactly what they saw before, and indented code blocks, paragraph continuation lines and list items render as they always have. Content of a blockquote is left alone to keep its current behavior. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
13 of 15 tasks
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 #1096.
A raw HTML block whose start tag is indented by more than three spaces and sits inside a containing block (a list item, an admonition, etc.) was not extracted by the HTML block preprocessor, because at that point the indentation cannot be told apart from an indented code block. The block parser then treated the HTML as inline content and split it into separate paragraphs at every blank line.
This takes the "container" approach prototyped by @facelessuser in
facelessuser/markdown(branchhtml-indent). Once a container has removed its own indentation, a block which starts with a block level tag can only be a raw block, so a newRawHtmlBlockProcessorextracts it there using the same extractor as the preprocessor, or themd_in_htmlextractor when that extension is enabled. Containers pass their content on a block at a time, so a raw block containing blank lines is collected across calls, keyed by the container, until it is closed, andRawHtmlFlushTreeprocessorfinishes anything still open once the document has been parsed. The preprocessor is not modified, so extensions which work on the document text before it is parsed see exactly what they saw before. Content of a blockquote is deliberately left alone to keep its current behavior.The two implementation commits are @facelessuser's, included unmodified and with their original authorship:
Extract raw HTML blocks nested in containers in a block processorandHandle elements under blockquotes and fix comments. The third commit only adds the changelog entry. The approach is considerably simpler than the treeprocessor-based one in #1666, which this PR supersedes.Verification
python -m unittest discover testspasses: 1310 tests, 111 skipped, 0 failures.flake8reports nothing on the touched source files.The behavior was also checked by rendering the same three inputs against the parent commit and against this branch. A raw block with a blank line inside a list item was rendered as
<p><div>/<p>secondparagraphs before and as a single<div>after; the same input inside a blockquote likewise; a four-space indented code block containing the same markup is unchanged in both, still escaped inside<pre><code>.AI Assistance Disclosure
No AI tools were used in preparing this PR.
AI tools were used and I have disclosed which ones, and have fully reviewed and verified their output.
AI tools were use to assist with the following:
Claude was used to write the PR description, the changelog entry, and the message of the changelog commit. The implementation commits were authored by @facelessuser in his fork; he disclosed in Fix HTML blocks nested in indented blocks #1666 that he used AI to compile the list of cases that should pass while prototyping. I ran the test suite and the before/after renders myself and can explain any part of the change.
Checklist