diff --git a/docling/backend/msword_backend.py b/docling/backend/msword_backend.py index 48d32809..ac6170b8 100644 --- a/docling/backend/msword_backend.py +++ b/docling/backend/msword_backend.py @@ -1145,6 +1145,9 @@ class MsWordDocumentBackend(DeclarativeDocumentBackend): elem_ref: list[RefItem] = [] # This should not happen by construction if not isinstance(self.parents[level], ListGroup): + _log.warning( + "Parent element of the list item is not a ListGroup. The list item will be ignored." + ) return elem_ref if not elements: return elem_ref @@ -1197,7 +1200,9 @@ class MsWordDocumentBackend(DeclarativeDocumentBackend): level = self._get_level() prev_indent = self._prev_indent() - if self._prev_numid() is None: # Open new list + if self._prev_numid() is None or ( + self._prev_numid() == numid and self.level_at_new_list is None + ): # Open new list self.level_at_new_list = level # Reset counters for the new numbering sequence @@ -1285,6 +1290,8 @@ class MsWordDocumentBackend(DeclarativeDocumentBackend): self._add_formatted_list_item( doc, elements, enum_marker, is_numbered, level - 1 ) + else: + _log.warning("List item not matching any insert condition.") return elem_ref @staticmethod diff --git a/tests/data/docx/list_after_num_headers.docx b/tests/data/docx/list_after_num_headers.docx new file mode 100644 index 00000000..4c9a83af Binary files /dev/null and b/tests/data/docx/list_after_num_headers.docx differ diff --git a/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.itxt b/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.itxt new file mode 100644 index 00000000..1f5decb0 --- /dev/null +++ b/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.itxt @@ -0,0 +1,9 @@ +item-0 at level 0: unspecified: group _root_ + item-1 at level 1: text: + item-2 at level 1: section: group header-0 + item-3 at level 2: section: group header-1 + item-4 at level 3: section_header: Chính sách bảo hành + item-5 at level 4: section_header: 1 ĐỐI TƯỢNG ÁP DỤNG + item-6 at level 5: list: group list + item-7 at level 6: list_item: Chính sách bảo hành và các điều k + item-8 at level 6: list_item: Pin điện áp cao (sau đây gọi tắt là “ \ No newline at end of file diff --git a/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.json b/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.json new file mode 100644 index 00000000..f0e81638 --- /dev/null +++ b/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.json @@ -0,0 +1,173 @@ +{ + "schema_name": "DoclingDocument", + "version": "1.8.0", + "name": "list_after_num_headers", + "origin": { + "mimetype": "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "binary_hash": 8533346410935061397, + "filename": "list_after_num_headers.docx" + }, + "furniture": { + "self_ref": "#/furniture", + "children": [], + "content_layer": "furniture", + "name": "_root_", + "label": "unspecified" + }, + "body": { + "self_ref": "#/body", + "children": [ + { + "$ref": "#/texts/0" + }, + { + "$ref": "#/groups/0" + } + ], + "content_layer": "body", + "name": "_root_", + "label": "unspecified" + }, + "groups": [ + { + "self_ref": "#/groups/0", + "parent": { + "$ref": "#/body" + }, + "children": [ + { + "$ref": "#/groups/1" + } + ], + "content_layer": "body", + "name": "header-0", + "label": "section" + }, + { + "self_ref": "#/groups/1", + "parent": { + "$ref": "#/groups/0" + }, + "children": [ + { + "$ref": "#/texts/1" + } + ], + "content_layer": "body", + "name": "header-1", + "label": "section" + }, + { + "self_ref": "#/groups/2", + "parent": { + "$ref": "#/texts/2" + }, + "children": [ + { + "$ref": "#/texts/3" + }, + { + "$ref": "#/texts/4" + } + ], + "content_layer": "body", + "name": "list", + "label": "list" + } + ], + "texts": [ + { + "self_ref": "#/texts/0", + "parent": { + "$ref": "#/body" + }, + "children": [], + "content_layer": "body", + "label": "text", + "prov": [], + "orig": "", + "text": "" + }, + { + "self_ref": "#/texts/1", + "parent": { + "$ref": "#/groups/1" + }, + "children": [ + { + "$ref": "#/texts/2" + } + ], + "content_layer": "body", + "label": "section_header", + "prov": [], + "orig": "Chính sách bảo hành", + "text": "Chính sách bảo hành", + "level": 2 + }, + { + "self_ref": "#/texts/2", + "parent": { + "$ref": "#/texts/1" + }, + "children": [ + { + "$ref": "#/groups/2" + } + ], + "content_layer": "body", + "label": "section_header", + "prov": [], + "orig": "1 ĐỐI TƯỢNG ÁP DỤNG", + "text": "1 ĐỐI TƯỢNG ÁP DỤNG", + "level": 3 + }, + { + "self_ref": "#/texts/3", + "parent": { + "$ref": "#/groups/2" + }, + "children": [], + "content_layer": "body", + "label": "list_item", + "prov": [], + "orig": "Chính sách bảo hành và các điều k", + "text": "Chính sách bảo hành và các điều k", + "formatting": { + "bold": false, + "italic": false, + "underline": false, + "strikethrough": false, + "script": "baseline" + }, + "enumerated": false, + "marker": "" + }, + { + "self_ref": "#/texts/4", + "parent": { + "$ref": "#/groups/2" + }, + "children": [], + "content_layer": "body", + "label": "list_item", + "prov": [], + "orig": "Pin điện áp cao (sau đây gọi tắt là “", + "text": "Pin điện áp cao (sau đây gọi tắt là “", + "formatting": { + "bold": false, + "italic": false, + "underline": false, + "strikethrough": false, + "script": "baseline" + }, + "enumerated": false, + "marker": "" + } + ], + "pictures": [], + "tables": [], + "key_value_items": [], + "form_items": [], + "pages": {} +} \ No newline at end of file diff --git a/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.md b/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.md new file mode 100644 index 00000000..6730ab9f --- /dev/null +++ b/tests/data/groundtruth/docling_v2/list_after_num_headers.docx.md @@ -0,0 +1,6 @@ +### Chính sách bảo hành + +#### 1 ĐỐI TƯỢNG ÁP DỤNG + +- Chính sách bảo hành và các điều k +- Pin điện áp cao (sau đây gọi tắt là “ \ No newline at end of file