Skip to content

Commit

Permalink
fix: simplify test and address broken test
Browse files Browse the repository at this point in the history
Signed-off-by: Yusik Kim <[email protected]>
  • Loading branch information
kmyusk committed Feb 19, 2025
1 parent 69350aa commit a241ebc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 173 deletions.
10 changes: 7 additions & 3 deletions docling_core/types/doc/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -2778,7 +2778,7 @@ def _image_fallback(item: TextItem):

# Building a math equation in MathML format
# ref https://www.w3.org/TR/wai-aria-1.1/#math
elif formula_to_mathml and img_fallback is not None:
elif formula_to_mathml:
try:
mathml_element = latex2mathml.converter.convert_to_element(
math_formula, display="block"
Expand All @@ -2794,9 +2794,13 @@ def _image_fallback(item: TextItem):
"Malformed formula cannot be rendered. "
f"Error {err.__class__.__name__}, formula={math_formula}"
)
if image_mode == ImageRefMode.EMBEDDED and len(item.prov) > 0:
if (
image_mode == ImageRefMode.EMBEDDED
and len(item.prov) > 0
and img_fallback is not None
):
text = img_fallback
else:
elif len(math_formula) > 0:
text = f"<pre>{math_formula}</pre>"

elif math_formula != "":
Expand Down
19 changes: 19 additions & 0 deletions test/test_docling_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,25 @@ def test_formula_mathml():
assert doc_html == gt_html


def test_formula_with_missing_fallback():
doc = DoclingDocument(name="Dummy")
bbox = BoundingBox.from_tuple((1, 2, 3, 4), origin=CoordOrigin.BOTTOMLEFT)
prov = ProvenanceItem(page_no=1, bbox=bbox, charspan=(0, 2))
doc.add_text(label=DocItemLabel.FORMULA, text="", orig="(II.24) 2 Imar", prov=prov)

actual = doc.export_to_html(
formula_to_mathml=True, html_head="", image_mode=ImageRefMode.EMBEDDED
)

expected = """<!DOCTYPE html>
<html lang="en">
<div class="formula-not-decoded">Formula not decoded</div>
</html>"""

assert actual == expected


def test_docitem_get_image():
# Prepare the document
doc = DoclingDocument(name="Dummy")
Expand Down
170 changes: 0 additions & 170 deletions test/test_export_to_html.py

This file was deleted.

0 comments on commit a241ebc

Please sign in to comment.