Repository navigation
Conversation
|
✅ DCO Check Passed Thanks @Jojoussef, 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 This PR fixes nested list structure flattening in DOCX files when empty spacing paragraphs appear between list items. It adds a snapshot/restore mechanism ( CI safety: no concern found. A maintainer must still approve CI. Possible duplicates
The |
In DOCX files, empty paragraphs between list items cleared list hierarchy state in MsWordDocumentBackend._handle_text_elements. When the subsequent sub-item arrived, _prev_numid and _prev_indent returned None. This caused _manage_list_structure to add sub-items as flat siblings in the root list group instead of nesting them under the preceding ListItem. Snapshot active list hierarchy state before processing empty spacing paragraphs and restore it when the list resumes with matching numId or indentation. Deferred empty paragraphs between list items are tracked and deleted at the end of conversion. Fixes docling-project#4947 Signed-off-by: Youssef Benatti <[email protected]>
beae89b to
a27ddbe
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Closing this as a duplicate of #4951, which fixes the same bug (#4947) and was opened two days earlier. Both patches change the same lines in Two points from this version are useful input:
Thanks for the clear repro. The best outcome is one fix that has the strengths of both. Please join the review on #4951, and if your test case covers something it misses, suggest it there. @taran-dev4u can add it with a |
Overview
In DOCX documents, empty spacing paragraphs placed between list items cleared list hierarchy state in
MsWordDocumentBackend._handle_text_elements. When the next sub-item (w:ilvl > 0) was encountered,_prev_numid()and_prev_indent()returnedNone, causing_manage_list_structureto add sub-items as flat siblings at level 0 instead of nesting them under their parentListItem.Fixes #4947.
Implementation details
docling/backend/msword_backend.py, added list state snapshotting (_save_list_state,_restore_saved_list_state, and_discard_saved_list_state).MsWordDocumentBackendpreserves the active list hierarchy (parents,level_at_new_list,level_start_ilevel,nested_lists, and indentation history)._manage_list_structureto nest sub-items under their preceding parent item._pending_list_empty_paragraphsand transferred to_deferred_empty_paragraphs, ensuring they are removed at the end of conversion.Testing
test_nested_list_items_separated_by_empty_paragraphs_preserve_nestingintests/test_backend_msword.py.ilvl=1separated by empty paragraphs nest under theirilvl=0parent in the document tree.