Repository navigation
fix: recognize single-block list items as ListItem - #4484
Conversation
|
Low, non-blocking — preserve cross-page nested items during page-grouped HTML export. This change can expose an existing exporter edge case when a nested list item is assigned to a different page from its parent. This is limited to cross-page hierarchy plus page-grouped HTML export and should not block this PR. A follow-up can preserve missing-parent items as page-local roots or continuation children, with a partition-to-export regression covering same-page, cross-page, and (authored by codex) |
cragwolfe
left a comment
There was a problem hiding this comment.
The core list-item classification change looks good. The cross-page page-grouped HTML-export edge case noted separately is non-blocking and can be handled as a follow-up.
(authored by codex)
Summary
Resolves #3499.
A
<li>whose only content is a single ordinary text block (<li><p>text</p></li>) now produces aListItem. This is the HTML that Markdown loose lists (items separated by blank lines) compile to, with bothmarkdownandmarkdown-it-py, sopartition_md()on a loose list returnedText/NarrativeText/Titleelements instead ofListItems.This implements the approach proposed in the issue thread: when a
<li>contains exactly one block element, adopt that block's content as the list item's text.Change
ListItemBlock.iter_elements()inunstructured/partition/html/parser.pyadopts the child block only when all of the following hold, otherwise it falls through to the existingFlow.iter_elements()traversal:<li>has no text of its own and exactly one child element,Flow/BlockItem(<p>,<div>,<blockquote>) — not a heading,<pre>, image, table, or nested list,The adopted element is built with the
<li>'s own accumulator, socategory_depthreflects list nesting, and inline annotations (links, emphasis) anddata-page-numberon the child are preserved.Before / after
Before:
After:
Tight lists are unchanged.
Testing
test_unstructured/partition/html/test_parser.py::DescribeListItemBlock— adoption for<p>/<div>/<blockquote>, annotation and nested-depth preservation, page-number inheritance, and 14 cases that must keep normal traversal (multiple paragraphs, prefix/suffix text, nested list,<pre>, heading, table, image,<figure>, whitespace-only block, plain text).test_unstructured/partition/test_md.py::test_partition_md_recognizes_loose_and_tight_lists— end-to-end for ordered and unordered lists, tight and loose.test_unstructured/partition/html+test_md.pysuites pass locally; the broadertest_unstructuredrun has the same result set asmainin my environment.