mirror of
https://github.com/DS4SD/docling.git
synced 2025-12-08 12:48:28 +00:00
fix: fix header levels for DOCX & HTML (#184)
Signed-off-by: Panos Vagenas <35837085+vagenas@users.noreply.github.com>
This commit is contained in:
30
tests/test_backend_msword.py
Normal file
30
tests/test_backend_msword.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from pathlib import Path
|
||||
|
||||
from docling.backend.msword_backend import MsWordDocumentBackend
|
||||
from docling.datamodel.base_models import InputFormat
|
||||
from docling.datamodel.document import InputDocument, SectionHeaderItem
|
||||
|
||||
|
||||
def test_heading_levels():
|
||||
in_path = Path("tests/data/word_sample.docx")
|
||||
in_doc = InputDocument(
|
||||
path_or_stream=in_path,
|
||||
format=InputFormat.DOCX,
|
||||
backend=MsWordDocumentBackend,
|
||||
)
|
||||
backend = MsWordDocumentBackend(
|
||||
in_doc=in_doc,
|
||||
path_or_stream=in_path,
|
||||
)
|
||||
doc = backend.convert()
|
||||
|
||||
found_lvl_1 = found_lvl_2 = False
|
||||
for item, _ in doc.iterate_items():
|
||||
if isinstance(item, SectionHeaderItem):
|
||||
if item.text == "Let\u2019s swim!":
|
||||
found_lvl_1 = True
|
||||
assert item.level == 1
|
||||
elif item.text == "Let\u2019s eat":
|
||||
found_lvl_2 = True
|
||||
assert item.level == 2
|
||||
assert found_lvl_1 and found_lvl_2
|
||||
Reference in New Issue
Block a user