fix: handle missing m:t text in OMML math runs (fixes #1512)#1668
Open
octo-patch wants to merge 3 commits intomicrosoft:mainfrom
Open
fix: handle missing m:t text in OMML math runs (fixes #1512)#1668octo-patch wants to merge 3 commits intomicrosoft:mainfrom
octo-patch wants to merge 3 commits intomicrosoft:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1512
Problem
When converting a DOCX file with mathematical equations, if any
m:relement inside anoMathblock has nom:tchild (for example, a formatting-only run containing onlym:rPr),ElementTree.findtext()returnsNone. Thedo_rmethod inomml.pythen does:This
TypeErrorpropagates up through_pre_process_math→pre_process_docx, where a file-leveltry/exceptcatches it and falls back to the raw, unmodified DOCX XML. Since mammoth cannot render OMML markup, all equations in the document silently disappear from the converted markdown output.Solution
omml.py—do_r: use(elm.findtext(...) or "")so an absentm:telement yields an empty string instead of crashing.pre_process.py—_pre_process_math: wrap each individual equation replacement in its owntry/exceptwith a warning log. This means a single un-convertible equation no longer causes every other equation in the document to be lost.Testing
test_docx_equationscontinues to pass.test_docx_equations_omit_empty_rundirectly exercises anm:rwith onlym:rPr(nom:t) and asserts that the surrounding equation is still converted to$x$.