Skip to content

fix(docx): close an open list before a heading - #4841

Open
LindseyZ1205 wants to merge 1 commit into
docling-project:mainfrom
LindseyZ1205:fix/docx-heading-after-list
Open

LindseyZ1205 wants to merge 1 commit into
docling-project:mainfrom
LindseyZ1205:fix/docx-heading-after-list

Conversation

@LindseyZ1205

@LindseyZ1205 LindseyZ1205 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What: In a DOCX file, a heading that comes right after a list is added inside the list group, so the HTML export puts it in the <ul> and the chunker merges it into the list's chunk.

Why: the backend only closed an open list before a table or body text. The heading branch now closes it too, with the steps #5309 added for tables, moved into _close_open_list().

Issue resolved by this Pull Request:
Resolves #4840

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

  • Before, in the issue example: <ul><li>point one</li><li>point two</li><h4>Details</h4><p>Body of the details section.</p></ul>, and one chunk with the list, the heading and its body. After: <ul><li>point one</li><li>point two</li></ul>, and the chunks '- point one\n- point two' (['Overview']) and 'Body of the details section.' (['Overview', 'Details']).
  • Document tree: only a heading that follows an open list, and the content under it, get a new parent. No reference data changes.
  • New test test_heading_after_a_list_is_not_in_the_list (a heading that skips a level after a list, and a list before the first heading): fails without this change and passes with it.
  • pytest tests/test_backend_msword*.py without test_e2e_docx_conversions: 338 passed, 2 failed. The same 2 fail on main with my docling-core 2.100.0. ruff passes, and ty reports the same as on main.
  • Not run: test_e2e_docx_conversions (its ground truth needs docling-core 2.106.0 or later) and the full test suite.

@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

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

@mergify

mergify Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 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)(?:\(.+\))?(!)?:

@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 labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

Warning

The AI analysis did not finish. Only the deterministic checks are shown.

CI safety: not assessed.

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 a9c6440161. It read the code and did not run it.

I found no defect that should stop the merge. In _handle_text_elements, the change clears self.parents from level_at_new_list before _add_heading. I traced both cases in the test (heading level skipped after a list, and a list before the first heading) through _get_level and _add_heading. Both gave the old wrong parent before the change and the correct parent after it.

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 15, 2026
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@PeterStaar-IBM

Copy link
Copy Markdown
Member

you probably can re-use the work done here: #5309

@PeterStaar-IBM

Copy link
Copy Markdown
Member

Hi @LindseyZ1205, thank you for this pull request.

It has a merge conflict with main. Please rebase your branch on the latest main and resolve the conflict:

git fetch upstream
git rebase upstream/main
# resolve the conflicts, then:
git push --force-with-lease

We can continue with the review and CI after that.

A heading paragraph did not close an open list, and _add_heading
clears the parents tail only for a lower heading level. So when a list
came before the first heading, or a heading skipped a level after a
list (for example Heading 1, a list, then Heading 3), the heading and
the text under it became children of the ListGroup. This gave invalid
HTML (<h4> inside <ul>) and put the section into the list chunk.

Close the list before the heading with the same steps as before a
table (docling-project#5309), which are now in _close_open_list().

Signed-off-by: LindseyZ1205 <[email protected]>
@LindseyZ1205
LindseyZ1205 force-pushed the fix/docx-heading-after-list branch from a9c6440 to 2b014e9 Compare November 27, 2026 18:00
@github-actions github-actions Bot removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Nov 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working docx issue related to docx backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX: a heading right after a list becomes a child of the ListGroup

2 participants