mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 12:48:28 +00:00
fix(docx): Missing list items after numbered header (#2665)
* fix #2250. list items after numbered headers Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * add test for new case Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> * chore(docx): remove unnecessary check Remove 'current_parent is None' check in '_add_list_item' function since it will always be None. Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> --------- Signed-off-by: Michele Dolfi <dol@zurich.ibm.com> Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com> Co-authored-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
This commit is contained in:
@@ -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
|
||||
|
||||
BIN
tests/data/docx/list_after_num_headers.docx
vendored
Normal file
BIN
tests/data/docx/list_after_num_headers.docx
vendored
Normal file
Binary file not shown.
9
tests/data/groundtruth/docling_v2/list_after_num_headers.docx.itxt
vendored
Normal file
9
tests/data/groundtruth/docling_v2/list_after_num_headers.docx.itxt
vendored
Normal file
@@ -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à “
|
||||
173
tests/data/groundtruth/docling_v2/list_after_num_headers.docx.json
vendored
Normal file
173
tests/data/groundtruth/docling_v2/list_after_num_headers.docx.json
vendored
Normal file
@@ -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": {}
|
||||
}
|
||||
6
tests/data/groundtruth/docling_v2/list_after_num_headers.docx.md
vendored
Normal file
6
tests/data/groundtruth/docling_v2/list_after_num_headers.docx.md
vendored
Normal file
@@ -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à “
|
||||
Reference in New Issue
Block a user