Skip to content

Keep a multi-line setext heading setext when re-rendering Markdown - #304

Merged
frostming merged 1 commit into
frostming:masterfrom
RavSinghChandan:setext-multiline-heading
Nov 9, 2026
Merged

frostming merged 1 commit into
frostming:masterfrom
RavSinghChandan:setext-multiline-heading

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

MarkdownRenderer renders every setext heading as an ATX heading. That only works when the heading is on one line; for a heading that spans lines, the lines after the first become a paragraph:

>>> md = marko.Markdown(renderer=MarkdownRenderer)
>>> md("Foo\nBar\n---\n")
'## Foo\nBar\n'
<!-- before -->
<h2>Foo
Bar</h2>
<!-- after re-rendering -->
<h2>Foo</h2>
<p>Bar</p>

With emphasis across the lines (Foo *bar\nbaz*\n====, spec example 81) the emphasis breaks too.

render_setext_heading() now keeps the setext form when the rendered heading contains a line break, with each line and the ===/--- underline prefixed for quotes and list items. One-line setext headings are still rendered as ATX headings, as before.

Added test_markdown_renderer_multiline_setext_heading with four cases (plain, emphasis across lines, in a quote, in a list item); they fail on master. Across the CommonMark spec examples, the number whose re-rendered Markdown gives different HTML goes from 27 to 24. 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

@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.

@frostming
frostming merged commit 1007779 into frostming:master Nov 9, 2026
19 of 20 checks passed
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