Skip to content

Keep the container prefix on every line of an HTML block when re-rendering Markdown - #303

Merged
frostming merged 1 commit into
frostming:masterfrom
RavSinghChandan:html-block-in-container
Nov 9, 2026
Merged

frostming merged 1 commit into
frostming:masterfrom
RavSinghChandan:html-block-in-container

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

MarkdownRenderer puts the quote marker or list indentation only on the first line of an HTML block. The other lines fall out of the container, so the re-rendered Markdown gives different HTML:

>>> md = marko.Markdown(renderer=MarkdownRenderer)
>>> md("> <details>\n> <summary>More</summary>\n> Hidden text\n> </details>\n")
'> <details>\n<summary>More</summary>\nHidden text\n</details>\n'

Here only <details> stays in the block quote. The same happens to a <div> or <table> in a list item and to a multi-line comment in a quote.

render_html_block() now prefixes every line like render_code_block() does, with an empty line getting the prefix without trailing spaces, as in #302. It also drops the block's trailing newline before splitting, like render_code_block(), so the block no longer ends with an extra blank line.

Added test_markdown_renderer_html_block_in_container with five cases; they fail on master. Across the CommonMark spec examples, the number whose re-rendered Markdown gives different HTML goes from 29 to 27. pytest tests, black, isort and flake8 pass, and mypy reports the same 5 errors as on master.

Used Claude (Opus) to help find and patch this; I reviewed and tested the change

@frostming
frostming merged commit cd9a62f into frostming:master Nov 9, 2026
18 checks passed
@human-attestation

Copy link
Copy Markdown

🛡️ Human Attestation required. A human needs to confirm this PR once before it can merge.

Attest this PR — sign in with GitHub, pass the challenge, and confirm one of the statements.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants