From f9dfcf075f131ac7359fcd6ba339e98758e0bb25 Mon Sep 17 00:00:00 2001 From: Sai Teja Bandaru Date: Sat, 11 Jul 2026 01:33:02 +0200 Subject: [PATCH] fix(docx): resolve math converter crash on empty runs in OMML to LaTeX conversion --- .../converter_utils/docx/math/omml.py | 8 ++++--- packages/markitdown/tests/test_module_misc.py | 23 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/markitdown/src/markitdown/converter_utils/docx/math/omml.py b/packages/markitdown/src/markitdown/converter_utils/docx/math/omml.py index dfa734cdc..dbad3923c 100644 --- a/packages/markitdown/src/markitdown/converter_utils/docx/math/omml.py +++ b/packages/markitdown/src/markitdown/converter_utils/docx/math/omml.py @@ -373,9 +373,11 @@ def do_r(self, elm): @todo \text (latex pure text support) """ _str = [] - for s in elm.findtext("./{0}t".format(OMML_NS)): - # s = s if isinstance(s,unicode) else unicode(s,'utf-8') - _str.append(self._t_dict.get(s, s)) + text = elm.findtext("./{0}t".format(OMML_NS)) + if text is not None: + for s in text: + # s = s if isinstance(s,unicode) else unicode(s,'utf-8') + _str.append(self._t_dict.get(s, s)) return escape_latex(BLANK.join(_str)) tag2meth = { diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py index 4d62e4919..1c2f2e4d6 100644 --- a/packages/markitdown/tests/test_module_misc.py +++ b/packages/markitdown/tests/test_module_misc.py @@ -532,6 +532,28 @@ def test_markitdown_llm() -> None: validate_strings(result, PPTX_TEST_STRINGS) +def test_docx_empty_math_run() -> None: + from xml.etree import ElementTree as ET + from markitdown.converter_utils.docx.math.omml import oMath2Latex + + # Create OMML XML string containing an empty run with no text child + omml_str = """ + + + + + + x + + + """ + + math_element = ET.fromstring(omml_str) + # This should not raise a TypeError: 'NoneType' object is not iterable + latex_converter = oMath2Latex(math_element) + assert latex_converter.latex == "x" + + if __name__ == "__main__": """Runs this file's tests from the command line.""" for test in [ @@ -547,6 +569,7 @@ def test_markitdown_llm() -> None: test_markitdown_exiftool, test_markitdown_llm_parameters, test_markitdown_llm, + test_docx_empty_math_run, ]: print(f"Running {test.__name__}...", end="") test()