fix: fix header levels for DOCX & HTML (#184)

Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
This commit is contained in:
Panos Vagenas
2024-10-28 17:02:52 +01:00
committed by GitHub
parent 94d0729c50
commit b9f5c74a7d
4 changed files with 75 additions and 28 deletions

View File

@@ -0,0 +1,30 @@
from pathlib import Path
from docling.backend.html_backend import HTMLDocumentBackend
from docling.datamodel.base_models import InputFormat
from docling.datamodel.document import InputDocument, SectionHeaderItem
def test_heading_levels():
in_path = Path("tests/data/wiki_duck.html")
in_doc = InputDocument(
path_or_stream=in_path,
format=InputFormat.HTML,
backend=HTMLDocumentBackend,
)
backend = HTMLDocumentBackend(
in_doc=in_doc,
path_or_stream=in_path,
)
doc = backend.convert()
found_lvl_2 = found_lvl_3 = False
for item, _ in doc.iterate_items():
if isinstance(item, SectionHeaderItem):
if item.text == "Etymology":
found_lvl_2 = True
assert item.level == 2
elif item.text == "Feeding":
found_lvl_3 = True
assert item.level == 3
assert found_lvl_2 and found_lvl_3