From 972112c07929faaeb99cf8f458fd6dd5c42fb07f Mon Sep 17 00:00:00 2001 From: Afloat Date: Sat, 21 Nov 2026 11:22:14 +0800 Subject: [PATCH] feat(html): retain common presentation MathML without TeX annotations --- .../partition/html/test_parser.py | 4 +- .../partition/html/test_partition.py | 4 +- .../html/test_presentation_mathml.py | 74 +++++++++++++ unstructured/partition/html/mathml.py | 100 ++++++++++++++++++ unstructured/partition/html/parser.py | 3 +- 5 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 test_unstructured/partition/html/test_presentation_mathml.py create mode 100644 unstructured/partition/html/mathml.py diff --git a/test_unstructured/partition/html/test_parser.py b/test_unstructured/partition/html/test_parser.py index 37014f18f3..9ca24b0b3c 100644 --- a/test_unstructured/partition/html/test_parser.py +++ b/test_unstructured/partition/html/test_parser.py @@ -1534,14 +1534,14 @@ class DescribeMath: """ @pytest.mark.parametrize("wrapper", ["{}", "{}", "{}"]) - def it_skips_mathml_that_has_no_text_representation_but_not_its_tail(self, wrapper: str): + def it_preserves_presentation_mathml_and_its_tail(self, wrapper: str): html = "
Before {} after.
".format( wrapper.format("x=2") ) div = etree.fromstring(html, html_parser).xpath(".//div")[0] assert isinstance(div.xpath(".//math")[0], Math) - assert [e.text for e in div.iter_elements()] == ["Before after."] + assert [e.text for e in div.iter_elements()] == ["Before x=2 after."] class DescribeRemovedPhrasing: diff --git a/test_unstructured/partition/html/test_partition.py b/test_unstructured/partition/html/test_partition.py index 26379f14ec..00a5472a86 100644 --- a/test_unstructured/partition/html/test_partition.py +++ b/test_unstructured/partition/html/test_partition.py @@ -894,7 +894,7 @@ def test_partition_html_keeps_katex_html_of_unusable_mathml_inside_an_unrecogniz wrapper.format( "Before" ' ' - 'x' + 'x' '" @@ -2223,7 +2223,7 @@ def test_partition_html_keeps_katex_html_when_mathml_is_unusable(): - x + x