Skip to content

🐛 fix(markdown): keep block content in headings - #1214

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/markdown-heading-blocks
Oct 8, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/markdown-heading-blocks

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

to_markdown let a block inside a heading break out of it. <h3><p>x</p></h3> became an empty ### followed by a paragraph x, and in <h2>a<p>b</p>c</h2> the b and c left the heading as a separate paragraph bc. 🐛

An ATX heading holds one line of inline content, so blocks inside a heading now flatten onto that line, the way link text already flattens them: the two examples give ### x and ## a b c. The end of a flattened block now reads as a space as well as its start, so link text over <div><i>a</i><i>b</i></div>x keeps a space before x where the b and x used to fuse.

markdownify 1.2.3 flattens the same way and gives ### x; html2text 2025.4.15 writes the empty ### and moves the content out, as turbohtml did. A heading nested in a heading now joins the outer heading's line, since Markdown has no nested headings.

The Markdown meaning check that runs over the #1018 fuzz consumers now compares heading content as one line too, with each block edge and <br> read as a space, since that is the only heading a reader can rebuild.

@gaborbernat gaborbernat added the bug Something isn't working label Oct 7, 2026
@gaborbernat
gaborbernat force-pushed the fix/markdown-heading-blocks branch 2 times, most recently from fe45efa to 105118a Compare October 7, 2026 23:47
@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 3 benchmarks

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 3 regressed benchmarks
✅ 576 untouched benchmarks
⏩ 32 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_feature[phone-ucs4-prose] 1.3 ms 1.4 ms -7.65%
❌ test_feature[phone-ucs2-prose] 2.1 ms 2.2 ms -6.55%
❌ test_feature[select-relative-sibling] 42.7 µs 45 µs -5.29%
⚡ test_feature[shadow-slot-comments] 137.9 µs 83.4 µs +65.28%
⚡ test_feature[form-data-fieldsets] 32.5 µs 30.9 µs +5.18%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing gaborbernat:fix/markdown-heading-blocks (3cfb39f) with main (2ffa2f0)

Open in CodSpeed

Footnotes

  1. 32 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

to_markdown let a block inside a heading break out of it. <h3><p>x</p>
</h3> became an empty "### " followed by a paragraph, and in
<h2>a<p>b</p>c</h2> the text after the block left the heading too.

A Markdown heading is one line, so blocks inside it now flatten onto
that line, the way link text already flattens them. The end of a
flattened block reads as a space as well as its start, so words on
either side of a block stay apart in headings and link text alike.
The Markdown meaning check compared the blocks nested in a heading as
blocks. A CommonMark heading holds one line of inline content, so no
conversion can keep those blocks, and the flattened heading this branch
writes still failed the check.

The check now flattens heading content onto one line, reading each block
edge and each <br> as a space, which is the heading a reader rebuilds
from the converted Markdown.
@gaborbernat
gaborbernat force-pushed the fix/markdown-heading-blocks branch from 982954c to 3cfb39f Compare October 8, 2026 01:27
@gaborbernat
gaborbernat merged commit a8e2c8f into tox-dev:main Oct 8, 2026
57 of 58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant