Repository navigation
fix(docx): close an open list before a table that follows it - #5309
PeterStaar-IBM merged 1 commit into
Conversation
Signed-off-by: Dhriman Deka <[email protected]>
|
✅ DCO Check Passed Thanks @astroknot-sheep, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit The PR adds Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at fc54a79bb7. It read the code and did not run it.
I found no defect that decides the merge. _close_list_before_table() in docling/backend/msword_backend.py copies the paragraph list-closing steps. It runs only for multi-cell tables, after the single-cell early return. It sets last_numid and nested_lists, clears the list-group cache, resets parents/level/level_at_new_list, and records history with a None numid. The history entry makes the next list item with the same numId reopen a fresh list. Table-cell lists keep their own state because _isolated_list_context restores it after each cell.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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]>
When a table comes directly after a list item in a Word document (no empty paragraph in between), the Word backend adds the table to the
ListGroup, as a sibling of the list items. In Markdown the table then gets glued onto the last item with no blank line, so most renderers show it as part of the list text, and a list item after the table goes back into the same list after the table.Paragraphs already close the open list; tables didn't. This adds
_close_list_before_table(), which does the same list-closing steps as the paragraph path (reset the parents fromlevel_at_new_list, drop the cached list group, record history) and is called before a multi-cell table is added. Single-cell tables are already unwrapped into body text, so they're unchanged. (#4305 fixed the variant with an empty paragraph between the list and the table.)Checklist:
Review evidence:
List Bulletparagraph followed by a 2×2 table gives aTableItemwhose parent is the list group; Markdown is- item\n| cell 00 | …(in the nested case the table sits inside the sub-list).ListGroups contain onlyListItems.test_table_right_after_a_list_closes_the_list(flat and nested) fails on main and passes with the fix.pytest tests/test_backend_msword*.py: 328 passed, includingtest_e2e_docx_conversionswith LibreOffice; no reference data changed.ruff format/ruff checkclean on the changed files.I used an AI assistant while working on this. I reproduced the bug, checked the document tree before and after, and ran the tests myself.