mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 12:48:28 +00:00
fix(html): use 'start' attribute when parsing ordered lists from HTML docs (#1062)
* fix(html): use 'start' attribute in ordered lists When parsing ordered lists in HTML, take into account the 'start' attribute if it exists. Signed-off-by: Cesar Berrospi Ramis <75900930+ceberam@users.noreply.github.com> * chore(html): reduce verbosity in HTML backend Signed-off-by: Cesar Berrospi Ramis <75900930+ceberam@users.noreply.github.com> --------- Signed-off-by: Cesar Berrospi Ramis <75900930+ceberam@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
37dd8c1cc7
commit
de7b963b09
@@ -1,4 +1,4 @@
|
||||
import os
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
|
||||
from docling.backend.html_backend import HTMLDocumentBackend
|
||||
@@ -41,6 +41,62 @@ def test_heading_levels():
|
||||
assert found_lvl_2 and found_lvl_3
|
||||
|
||||
|
||||
def test_ordered_lists():
|
||||
test_set: list[tuple[bytes, str]] = []
|
||||
|
||||
test_set.append(
|
||||
(
|
||||
b"<html><body><ol><li>1st item</li><li>2nd item</li></ol></body></html>",
|
||||
"1. 1st item\n2. 2nd item",
|
||||
)
|
||||
)
|
||||
test_set.append(
|
||||
(
|
||||
b'<html><body><ol start="1"><li>1st item</li><li>2nd item</li></ol></body></html>',
|
||||
"1. 1st item\n2. 2nd item",
|
||||
)
|
||||
)
|
||||
test_set.append(
|
||||
(
|
||||
b'<html><body><ol start="2"><li>1st item</li><li>2nd item</li></ol></body></html>',
|
||||
"2. 1st item\n3. 2nd item",
|
||||
)
|
||||
)
|
||||
test_set.append(
|
||||
(
|
||||
b'<html><body><ol start="0"><li>1st item</li><li>2nd item</li></ol></body></html>',
|
||||
"0. 1st item\n1. 2nd item",
|
||||
)
|
||||
)
|
||||
test_set.append(
|
||||
(
|
||||
b'<html><body><ol start="-5"><li>1st item</li><li>2nd item</li></ol></body></html>',
|
||||
"1. 1st item\n2. 2nd item",
|
||||
)
|
||||
)
|
||||
test_set.append(
|
||||
(
|
||||
b'<html><body><ol start="foo"><li>1st item</li><li>2nd item</li></ol></body></html>',
|
||||
"1. 1st item\n2. 2nd item",
|
||||
)
|
||||
)
|
||||
|
||||
for pair in test_set:
|
||||
in_doc = InputDocument(
|
||||
path_or_stream=BytesIO(pair[0]),
|
||||
format=InputFormat.HTML,
|
||||
backend=HTMLDocumentBackend,
|
||||
filename="test",
|
||||
)
|
||||
backend = HTMLDocumentBackend(
|
||||
in_doc=in_doc,
|
||||
path_or_stream=BytesIO(pair[0]),
|
||||
)
|
||||
doc: DoclingDocument = backend.convert()
|
||||
assert doc
|
||||
assert doc.export_to_markdown() == pair[1]
|
||||
|
||||
|
||||
def get_html_paths():
|
||||
|
||||
# Define the directory you want to search
|
||||
|
||||
Reference in New Issue
Block a user