Skip to content

Commit f23961c

Browse files
committed
sign off Signed-off-by: vtempest <[email protected]>
Signed-off-by: vtempest <[email protected]>
1 parent 51b8a76 commit f23961c

27 files changed

+335
-22
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [v2.34.1](https://github.com/docling-project/docling-core/releases/tag/v2.34.1) - 2025-06-08
2+
3+
### Fix
4+
5+
* Warn when adding misplaced ListItem via API ([#321](https://github.com/docling-project/docling-core/issues/321)) ([`01b27b5`](https://github.com/docling-project/docling-core/commit/01b27b57b32c8a1a23e65ce3bf60cd1c027ca915))
6+
17
## [v2.34.0](https://github.com/docling-project/docling-core/releases/tag/v2.34.0) - 2025-06-06
28

39
### Feature

docling_core/types/doc/document.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,10 @@ def add_list_item(
21672167
21682168
"""
21692169
if not isinstance(parent, (OrderedList, UnorderedList)):
2170-
raise ValueError("ListItem's parent must be a list group")
2170+
warnings.warn("ListItem's parent must be a list group.", DeprecationWarning)
2171+
2172+
if not parent:
2173+
parent = self.body
21712174

21722175
if not orig:
21732176
orig = text
@@ -4270,11 +4273,12 @@ def validate_misplaced_list_items(self):
42704273
item.parent.resolve(doc=self), (OrderedList, UnorderedList)
42714274
)
42724275
):
4273-
# non_group_list_items.append(item)
4274-
if prev is None or not isinstance(prev, ListItem): # if new list
4275-
misplaced_list_items.append([item])
4276-
else:
4276+
if isinstance(prev, ListItem) and (
4277+
prev.parent is None or prev.parent.resolve(self) == self.body
4278+
): # case of continuing list
42774279
misplaced_list_items[-1].append(item)
4280+
else: # case of new list
4281+
misplaced_list_items.append([item])
42784282
prev = item
42794283

42804284
for curr_list_items in reversed(misplaced_list_items):

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "docling-core"
3-
version = "2.34.0" # DO NOT EDIT, updated automatically
3+
version = "2.34.1" # DO NOT EDIT, updated automatically
44
description = "A python library to define and validate data types in Docling."
55
license = "MIT"
66
license-files = ["LICENSE"]

test/data/doc/constructed_doc.appended_child.json.gt

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@
6969
{
7070
"$ref": "#/groups/9"
7171
},
72+
{
73+
"$ref": "#/groups/12"
74+
},
7275
{
7376
"$ref": "#/texts/42"
7477
},
7578
{
76-
"$ref": "#/texts/43"
79+
"$ref": "#/texts/44"
7780
}
7881
],
7982
"content_layer": "body",
@@ -310,12 +313,26 @@
310313
"$ref": "#/texts/39"
311314
},
312315
{
313-
"$ref": "#/texts/44"
316+
"$ref": "#/texts/45"
314317
}
315318
],
316319
"content_layer": "body",
317320
"name": "list C",
318321
"label": "ordered_list"
322+
},
323+
{
324+
"self_ref": "#/groups/12",
325+
"parent": {
326+
"$ref": "#/body"
327+
},
328+
"children": [
329+
{
330+
"$ref": "#/texts/43"
331+
}
332+
],
333+
"content_layer": "body",
334+
"name": "group",
335+
"label": "list"
319336
}
320337
],
321338
"texts": [
@@ -947,6 +964,20 @@
947964
},
948965
{
949966
"self_ref": "#/texts/43",
967+
"parent": {
968+
"$ref": "#/groups/12"
969+
},
970+
"children": [],
971+
"content_layer": "body",
972+
"label": "list_item",
973+
"prov": [],
974+
"orig": "List item without parent list group",
975+
"text": "List item without parent list group",
976+
"enumerated": false,
977+
"marker": "-"
978+
},
979+
{
980+
"self_ref": "#/texts/44",
950981
"parent": {
951982
"$ref": "#/body"
952983
},
@@ -958,7 +989,7 @@
958989
"text": "child text appended at body"
959990
},
960991
{
961-
"self_ref": "#/texts/44",
992+
"self_ref": "#/texts/45",
962993
"parent": {
963994
"$ref": "#/groups/11"
964995
},

test/data/doc/constructed_doc.deleted_group.json.gt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@
7272
{
7373
"$ref": "#/groups/9"
7474
},
75+
{
76+
"$ref": "#/groups/12"
77+
},
7578
{
7679
"$ref": "#/texts/42"
7780
}
@@ -313,6 +316,20 @@
313316
"content_layer": "body",
314317
"name": "list C",
315318
"label": "ordered_list"
319+
},
320+
{
321+
"self_ref": "#/groups/12",
322+
"parent": {
323+
"$ref": "#/body"
324+
},
325+
"children": [
326+
{
327+
"$ref": "#/texts/43"
328+
}
329+
],
330+
"content_layer": "body",
331+
"name": "group",
332+
"label": "list"
316333
}
317334
],
318335
"texts": [
@@ -941,6 +958,20 @@
941958
"prov": [],
942959
"orig": "The end.",
943960
"text": "The end."
961+
},
962+
{
963+
"self_ref": "#/texts/43",
964+
"parent": {
965+
"$ref": "#/groups/12"
966+
},
967+
"children": [],
968+
"content_layer": "body",
969+
"label": "list_item",
970+
"prov": [],
971+
"orig": "List item without parent list group",
972+
"text": "List item without parent list group",
973+
"enumerated": false,
974+
"marker": "-"
944975
}
945976
],
946977
"pictures": [

test/data/doc/constructed_doc.deleted_picture.json.gt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
{
7070
"$ref": "#/groups/9"
7171
},
72+
{
73+
"$ref": "#/groups/12"
74+
},
7275
{
7376
"$ref": "#/texts/42"
7477
}
@@ -310,6 +313,20 @@
310313
"content_layer": "body",
311314
"name": "list C",
312315
"label": "ordered_list"
316+
},
317+
{
318+
"self_ref": "#/groups/12",
319+
"parent": {
320+
"$ref": "#/body"
321+
},
322+
"children": [
323+
{
324+
"$ref": "#/texts/43"
325+
}
326+
],
327+
"content_layer": "body",
328+
"name": "group",
329+
"label": "list"
313330
}
314331
],
315332
"texts": [
@@ -938,6 +955,20 @@
938955
"prov": [],
939956
"orig": "The end.",
940957
"text": "The end."
958+
},
959+
{
960+
"self_ref": "#/texts/43",
961+
"parent": {
962+
"$ref": "#/groups/12"
963+
},
964+
"children": [],
965+
"content_layer": "body",
966+
"label": "list_item",
967+
"prov": [],
968+
"orig": "List item without parent list group",
969+
"text": "List item without parent list group",
970+
"enumerated": false,
971+
"marker": "-"
941972
}
942973
],
943974
"pictures": [

test/data/doc/constructed_doc.deleted_text.json.gt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
{
7676
"$ref": "#/groups/13"
7777
},
78+
{
79+
"$ref": "#/groups/16"
80+
},
7881
{
7982
"$ref": "#/texts/51"
8083
}
@@ -396,6 +399,20 @@
396399
"content_layer": "body",
397400
"name": "list C",
398401
"label": "ordered_list"
402+
},
403+
{
404+
"self_ref": "#/groups/16",
405+
"parent": {
406+
"$ref": "#/body"
407+
},
408+
"children": [
409+
{
410+
"$ref": "#/texts/54"
411+
}
412+
],
413+
"content_layer": "body",
414+
"name": "group",
415+
"label": "list"
399416
}
400417
],
401418
"texts": [
@@ -1183,6 +1200,20 @@
11831200
"text": "new list item (after)",
11841201
"enumerated": false,
11851202
"marker": "-"
1203+
},
1204+
{
1205+
"self_ref": "#/texts/54",
1206+
"parent": {
1207+
"$ref": "#/groups/16"
1208+
},
1209+
"children": [],
1210+
"content_layer": "body",
1211+
"label": "list_item",
1212+
"prov": [],
1213+
"orig": "List item without parent list group",
1214+
"text": "List item without parent list group",
1215+
"enumerated": false,
1216+
"marker": "-"
11861217
}
11871218
],
11881219
"pictures": [

test/data/doc/constructed_doc.dt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@ Affiliation 2</text>
6767
</ordered_list></list_item>
6868
<list_item>Item 4 in A</list_item>
6969
</ordered_list>
70+
<unordered_list><list_item>List item without parent list group</list_item>
71+
</unordered_list>
7072
<text>The end.</text>
7173
</doctag>

test/data/doc/constructed_doc.dt.gt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,7 @@ Affiliation 2</text>
6767
</ordered_list></list_item>
6868
<list_item>Item 4 in A</list_item>
6969
</ordered_list>
70+
<unordered_list><list_item>List item without parent list group</list_item>
71+
</unordered_list>
7072
<text>The end.</text>
7173
</doctag>

test/data/doc/constructed_doc.embedded.html.gt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@
197197
</ol>
198198
<li>Item 4 in A</li>
199199
</ol>
200+
<ul>
201+
<li>List item without parent list group</li>
202+
</ul>
200203
<p>The end.</p>
201204
</div>
202205
</body>

test/data/doc/constructed_doc.embedded.json.gt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@
7575
{
7676
"$ref": "#/groups/13"
7777
},
78+
{
79+
"$ref": "#/groups/16"
80+
},
7881
{
7982
"$ref": "#/texts/52"
8083
}
@@ -393,6 +396,20 @@
393396
"content_layer": "body",
394397
"name": "list C",
395398
"label": "ordered_list"
399+
},
400+
{
401+
"self_ref": "#/groups/16",
402+
"parent": {
403+
"$ref": "#/body"
404+
},
405+
"children": [
406+
{
407+
"$ref": "#/texts/53"
408+
}
409+
],
410+
"content_layer": "body",
411+
"name": "group",
412+
"label": "list"
396413
}
397414
],
398415
"texts": [
@@ -1166,6 +1183,20 @@
11661183
"prov": [],
11671184
"orig": "The end.",
11681185
"text": "The end."
1186+
},
1187+
{
1188+
"self_ref": "#/texts/53",
1189+
"parent": {
1190+
"$ref": "#/groups/16"
1191+
},
1192+
"children": [],
1193+
"content_layer": "body",
1194+
"label": "list_item",
1195+
"prov": [],
1196+
"orig": "List item without parent list group",
1197+
"text": "List item without parent list group",
1198+
"enumerated": false,
1199+
"marker": "-"
11691200
}
11701201
],
11711202
"pictures": [

test/data/doc/constructed_doc.embedded.md.gt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ Some formatting chops: **bold** *italic* underline ~~strikethrough~~ subscript s
7373
3. Item 3 in B
7474
4. Item 4 in A
7575

76+
- List item without parent list group
77+
7678
The end.

0 commit comments

Comments
 (0)