Skip to content

fix(docx,iwork): put a sub-list under the list item above it - #4863

Merged
dolfim-ibm merged 1 commit into
docling-project:mainfrom
LubabaKhalid:fix/docx-nested-list-parent
Oct 19, 2026
Merged

dolfim-ibm merged 1 commit into
docling-project:mainfrom
LubabaKhalid:fix/docx-nested-list-parent

Conversation

@LubabaKhalid

Copy link
Copy Markdown
Contributor

The Word and iWork backends add a nested list as a child of the enclosing list group. The HTML, Markdown, PowerPoint and OpenDocument backends add it as a child of the list item above it. The group-child shape:

  • fails the docling-core rule that a ListGroup holds only list items (DoclingDocument._validate_rules() reports ListGroup ... contains non-ListItem ...);
  • makes export_to_html() write a <ul> or <ol> directly inside a <ul> or <ol>, which is not valid HTML.

This change adds a nested list group under the last list item of the enclosing group:

  • In the Word backend, _sub_list_parent() is used at the three places that open a nested list group: the w:ilvl path, the indentation path and a new list sequence.
  • In the iWork backend, _ListStack does the same.

When the enclosing group has no list item yet, the group stays the parent, as before.

Issue resolved by this Pull Request:
Resolves #4854

Checklist:

  • Documentation has been updated, if necessary. (Not needed.)
  • Examples have been added, if necessary. (Not needed.)
  • Tests have been added, if necessary.

Review evidence:

Measured over the 36 DOCX test sources in tests/data/docx/sources:

main This PR
Nested list groups under a list item 0 23
Nested list groups under a list group 23 0
<ul>/<ol> directly after </li> in export_to_html() 22 0
Documents that fail _validate_rules() with "contains non-ListItem" 5 0

Reference data: the .itxt and .json files of 5 DOCX documents change: docx_lists, docx_list_blank_spacer, docx_list_east_asian_num_fmt, unit_test_formatting and unit_test_headers_numbered. Each nested list moves one level down, under the list item above it. The item numbers, texts and markers do not change. No .md file changes.

Tests:

  • Five DOCX tests asserted the old shape (the sub-list group is a child of the outer group). They now assert that the sub-list group is a child of the list item above it.
  • test_sub_list_belongs_to_the_item_above_it is a new test. It builds an iWork '09 Pages document with three list levels. It fails on main.

Checks:

  • uv run pytest tests/test_backend_msword.py tests/test_backend_msword_lists.py tests/test_backend_msword_outline.py tests/test_backend_msword_spacer.py tests/test_backend_iwork_pages.py tests/test_backend_iwork_keynote.py: 402 passed, 1 skipped
  • uv run prek run --files <changed files>: all hooks passed

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @LubabaKhalid, all your commits are properly signed off. 🎉

@LubabaKhalid

Copy link
Copy Markdown
Contributor Author

@dolfim-ibm @DanielNg0729 could you please review this PR when you have time? Thank you!

@mergify

mergify Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 All 2 merge protections satisfied — ready to merge.

Show 2 satisfied protections

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

🟢 Require two reviewer for test updates

When test data is updated, we require two reviewers

  • #approved-reviews-by >= 2

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working docx issue related to docx backend iwork issue related to Apple's free productivity suite (iWork) format backend (Pages, Number, Keynote) labels Oct 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit c9f44148f4. The analysis read the diff only. It did not run code from this pull request.

The PR fixes both the DOCX and iWork backends so that a nested list group is added under the last list item of the enclosing group, not directly under the enclosing list group. This matches the behavior of the HTML, Markdown, PowerPoint, and ODF backends and passes _validate_rules().

Topic labels added: bug, docx, iwork.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4841 open changes the same code related: PR #4841 also changes the DOCX list code and the same test file, but it fixes a different bug: a heading after an open list is incorrectly nested inside the list group. The two PRs solve different problems and can both be merged.

Reference data changes

Change Files
text 10
  • text tests/data/docx/groundtruth/docx_list_blank_spacer.docx.itxt: +2 / -2 lines
  • text tests/data/docx/groundtruth/docx_list_blank_spacer.docx.json: item attributes changed
  • text tests/data/docx/groundtruth/docx_list_east_asian_num_fmt.docx.itxt: +6 / -6 lines
  • text tests/data/docx/groundtruth/docx_list_east_asian_num_fmt.docx.json: item attributes changed
  • text tests/data/docx/groundtruth/docx_lists.docx.itxt: +39 / -39 lines
  • text tests/data/docx/groundtruth/docx_lists.docx.json: item attributes changed
  • text tests/data/docx/groundtruth/unit_test_formatting.docx.itxt: +6 / -6 lines
  • text tests/data/docx/groundtruth/unit_test_formatting.docx.json: item attributes changed
  • text tests/data/docx/groundtruth/unit_test_headers_numbered.docx.itxt: +17 / -17 lines
  • text tests/data/docx/groundtruth/unit_test_headers_numbered.docx.json: item attributes changed

Assessment: expected. All 10 changed reference files are DOCX list documents. The .itxt and .json changes show nested list items moving one level down under their parent list item, which is exactly the structural change the PR implements.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at c9f44148f4. It read the code and did not run it.

The fix correctly moves nested list groups from being children of a ListGroup to being children of the last ListItem above them, matching the HTML/Markdown/PPTX/ODP backends. The _sub_list_parent helper is sound: when the enclosing group has no items yet it falls back to the group itself, and multi-level jumps are handled correctly because each newly appended group has no children when _sub_list_parent is called for the next level. Reference data changes are symmetric (same line counts added and removed), confirming no text was lost. The reviewer should verify that the _can_reuse_list_group cache check still works correctly now that last_list_group_parent can be a ListItem — it does, because _sub_list_parent returns the same ListItem on every resume of the same sub-list.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 16, 2026
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/iwork_backend.py 70.00% 1 Missing and 2 partials ⚠️
docling/backend/msword_backend.py 85.71% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@DanielNg0729 DanielNg0729 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dolfim-ibm dolfim-ibm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@dolfim-ibm
dolfim-ibm merged commit d54d4b8 into docling-project:main Oct 19, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working docx issue related to docx backend iwork issue related to Apple's free productivity suite (iWork) format backend (Pages, Number, Keynote)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX and iWork: nested lists are parented under the outer ListGroup instead of the last ListItem

3 participants