Repository navigation
🐛 fix(text): keep non-item list children - #1625
Conversation
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.
Merging this PR will degrade performance by 8.37%2 warnings
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
to_text()andto_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