Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
23 changes: 23 additions & 0 deletions packages/markitdown/tests/test_module_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<m:oMath xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math">
<m:r>
<m:rPr/>
</m:r>
<m:r>
<m:t>x</m:t>
</m:r>
</m:oMath>
"""

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 [
Expand All @@ -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()
Expand Down