Skip to content

Fix HTML blocks nested in indented blocks - #1666

Open
inchang-ing wants to merge 1 commit into
Python-Markdown:masterfrom
inchang-ing:fix/html-block-nested-indent
Open

inchang-ing wants to merge 1 commit into
Python-Markdown:masterfrom
inchang-ing:fix/html-block-nested-indent

Conversation

@inchang-ing

Copy link
Copy Markdown

Raw HTML blocks which start on a line indented by more than three spaces were not extracted by the HTML block preprocessor, as it could not distinguish such a start tag nested within a containing block (a list item, admonition, etc.) from an indented code block. The block parser then treated the HTML as inline content and split it into separate paragraphs at any blank lines within the raw block.

The preprocessor now extracts such indented raw blocks, removes the indentation of the start tag from the stashed content, and preserves that indentation on the line which holds the placeholder. The block parser can then make the decision based on the resulting block structure: within a containing block the placeholder is parsed as nested content, whereas an indented code block keeps the placeholder in its content. In the latter case, the RawHtmlPostprocessor escapes the stashed HTML, so indented code blocks are rendered exactly as before.

Fixes #1096

Description

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:

    • Code
    • Code Comments
    • Documentation
    • Changelog Entry
    • Commit Message
    • The Description Above
    • Other: ______________

Checklist

Raw HTML blocks which start on a line indented by more than three
spaces were not extracted by the HTML block preprocessor, as it could
not distinguish such a start tag nested within a containing block
(a list item, admonition, etc.) from an indented code block. The
block parser then treated the HTML as inline content and split it
into separate paragraphs at any blank lines within the raw block.

The preprocessor now extracts such indented raw blocks, removes the
indentation of the start tag from the stashed content, and preserves
that indentation on the line which holds the placeholder. The block
parser can then make the decision based on the resulting block
structure: within a containing block the placeholder is parsed as
nested content, whereas an indented code block keeps the placeholder
in its content. In the latter case, the RawHtmlPostprocessor escapes
the stashed HTML, so indented code blocks are rendered exactly as
before.

Fixes Python-Markdown#1096
@waylan

waylan commented Oct 20, 2026

Copy link
Copy Markdown
Member

Please edit your initial comment and check the appropriate boxes (add a x in the brackets like this [x]).

@waylan waylan added the more-info-needed More information needs to be provided. label Oct 20, 2026
@facelessuser

Copy link
Copy Markdown
Collaborator

I would like to see this tested with md_in_html as well. The testing seems generally sparse for such a potentially big change. I'd like to spend some time more thoroughly vetting this and seeing how it will impact 3rd party plugins as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

more-info-needed More information needs to be provided.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML block handling nested in indented blocks doesn't work properly

3 participants