Skip to content

🐛 fix(text): keep non-item list children - #1625

Merged
gaborbernat merged 2 commits into
mainfrom
fix/1621-list-children
Nov 5, 2026
Merged

gaborbernat merged 2 commits into
mainfrom
fix/1621-list-children

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

to_text() and to_annotated_text() dropped every child of a <ul> or <ol> that was not an <li>, so text and blocks between or after the items vanished while browsers show them (#1621). An unclosed list made it worse: the parser keeps everything after the last item inside the list, so the rest of the document went missing from the extracted text, about a fifth of one SEC filing in the report.

The text serializer now treats list content the way the Markdown serializer has since #864: content before the first item is a block of its own, content after an item continues that item indented under its marker, and an element wrapping <li> children is looked through so markers and numbering carry on. Plain and annotated text share that walk, so both keep the content.

 >>> parse("<p>a</p><ul><li>b</li><p>c</p><p>e</p>").to_text()
-'a\n\n* b'
+'a\n\n* b\n  c\n  e'
 >>> parse("<ul><li>b</li>tail</ul>").to_text()
-'* b'
+'* b\n  tail'

Closes #1621

to_text and to_annotated_text rendered only the li children of a ul or ol, so text and blocks between or after the items vanished, and an unclosed list lost the rest of the document. Such content now renders in place: before the first item as its own block, after an item indented under its marker. An element wrapping li items is looked through so the markers and numbering continue, as to_markdown does.
@gaborbernat
gaborbernat enabled auto-merge (squash) November 5, 2026 00:27
@gaborbernat gaborbernat added the bug Something isn't working label Nov 5, 2026
@codspeed

codspeed Bot commented Nov 5, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 8.37%

2 warnings

⚠️ 3 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 3 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 1 improved benchmark
❌ 2 regressed benchmarks
✅ 579 untouched benchmarks
⏩ 32 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_feature[shadow-slot-comments] 83.4 µs 110 µs -24.18%
❌ test_feature[select-relative-sibling] 41.1 µs 43.5 µs -5.36%
⚡ test_feature[linkify-traversal-wide-callbacks] 2.7 ms 2.5 ms +7.24%

Tip

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


Comparing fix/1621-list-children (2810797) with main (7daa2f5)

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

@gaborbernat
gaborbernat disabled auto-merge November 5, 2026 00:58
@gaborbernat
gaborbernat merged commit 0293b02 into main Nov 5, 2026
54 of 55 checks passed
@gaborbernat
gaborbernat deleted the fix/1621-list-children branch November 5, 2026 00:58
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.

to_text drops list children that are not <li>

1 participant