Skip to content

Commit 349f7da

Browse files
authored
fix(markdown): fix handling of ordered lists (#175)
Signed-off-by: Panos Vagenas <[email protected]>
1 parent b2c9746 commit 349f7da

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

docling_core/types/doc/document.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,11 +2489,16 @@ def _ingest_text(text: str, do_escape_html=True, do_escape_underscores=True):
24892489
)
24902490
# NOTE: assumes unordered (flag & marker currently in ListItem)
24912491
indent_str = list_level * indent * " "
2492+
is_ol = item.label == GroupLabel.ORDERED_LIST
24922493
text = "\n".join(
24932494
[
24942495
# avoid additional marker on already evaled sublists
2495-
cpt if cpt and cpt[0] == " " else f"{indent_str}- {cpt}"
2496-
for cpt in comps
2496+
(
2497+
c
2498+
if c and c[0] == " "
2499+
else f"{indent_str}{f'{i + 1}.' if is_ol else '-'} {c}"
2500+
)
2501+
for i, c in enumerate(comps)
24972502
]
24982503
)
24992504
_ingest_text(text=text)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This paper introduces the biggest invention ever made. ...
1515
- list item 1
1616
- list item 2
1717
- list item 3
18-
- list item 3.a
19-
- list item 3.b
20-
- list item 3.c
21-
- list item 3.c.i
18+
1. list item 3.a
19+
2. list item 3.b
20+
3. list item 3.c
21+
1. list item 3.c.i
2222
- list item 4
2323

2424
This is the caption of table 1.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This paper introduces the biggest invention ever made. ...
1515
- list item 1
1616
- list item 2
1717
- list item 3
18-
- list item 3.a
19-
- list item 3.b
20-
- list item 3.c
21-
- list item 3.c.i
18+
1. list item 3.a
19+
2. list item 3.b
20+
3. list item 3.c
21+
1. list item 3.c.i
2222
- list item 4
2323

2424
This is the caption of table 1.

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This paper introduces the biggest invention ever made. ...
1515
- list item 1
1616
- list item 2
1717
- list item 3
18-
- list item 3.a
19-
- list item 3.b
20-
- list item 3.c
21-
- list item 3.c.i
18+
1. list item 3.a
19+
2. list item 3.b
20+
3. list item 3.c
21+
1. list item 3.c.i
2222
- list item 4
2323

2424
This is the caption of table 1.

test/data/doc/constructed_document.yaml.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ This paper introduces the biggest invention ever made. ...
1515
- list item 1
1616
- list item 2
1717
- list item 3
18-
- list item 3.a
19-
- list item 3.b
20-
- list item 3.c
21-
- list item 3.c.i
18+
1. list item 3.a
19+
2. list item 3.b
20+
3. list item 3.c
21+
1. list item 3.c.i
2222
- list item 4
2323

2424
This is the caption of table 1.

0 commit comments

Comments
 (0)