Skip to content

Wrong numbering in markdown export of nested ordered lists #189

Closed
@ceberam

Description

@ceberam

Nested ordered lists are exported in markdown with a wrong number sequence.
After an inner list, the next item of the outer list does not show the right number in its marker.

To reproduce the issue, run the following snippet with the current docling-core version 2.22.0.

from docling_core.types.doc.document import DoclingDocument, DocItemLabel, GroupLabel

doc = DoclingDocument(name="file")
parent = doc.add_text(parent=None, label=DocItemLabel.TITLE, text="Test")
parent_A = doc.add_group(parent=parent, name="list A", label=GroupLabel.ORDERED_LIST)
doc.add_list_item(text="Item 1 in A", enumerated=True, parent=parent_A)
doc.add_list_item(text="Item 2 in A", enumerated=True, parent=parent_A)
item_A_3 = doc.add_list_item(text="Item 3 in A", enumerated=True, parent=parent_A) 

parent_B= doc.add_group(parent=item_A_3, name="list B", label=GroupLabel.ORDERED_LIST)
doc.add_list_item(text="Item 1 in B", enumerated=True, parent=parent_B)
doc.add_list_item(text="Item 2 in B", enumerated=True, parent=parent_B)

doc.add_list_item(text="Item 4 in A", enumerated=True, parent=parent_A) 
print(doc.export_to_markdown())

The print command shows:

# Test

1. Item 1 in A
2. Item 2 in A
3. Item 3 in A
    1. Item 1 in B
    2. Item 2 in B
5. Item 4 in A

while the correct output should be:

# Test

1. Item 1 in A
2. Item 2 in A
3. Item 3 in A
    1. Item 1 in B
    2. Item 2 in B
4. Item 4 in A

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions