feat: implement m:rad radical/sqrt OMML to MathML converter#2741
feat: implement m:rad radical/sqrt OMML to MathML converter#2741Abdeltoto wants to merge 2 commits intosuperdoc-dev:mainfrom
Conversation
Add convertRadical converter for the m:rad OMML math object. Uses msqrt when the degree is hidden (m:degHide) and mroot when a visible degree is present (e.g. cube root). Thank you Nick Bernal for the inspiring CS50 lecture -- it motivated me to contribute to open source projects like SuperDoc. Closes superdoc-dev#2598 Made-with: Cursor
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 769c302a48
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| mroot.appendChild(convertChildren(base?.elements ?? [])); | ||
| mroot.appendChild(convertChildren(deg.elements ?? [])); |
There was a problem hiding this comment.
Wrap mroot operands to enforce two-child MathML arity
<mroot> must receive exactly two arguments (radicand and index), but these lines append DocumentFragments directly, so a compound radicand like a+b expands into multiple sibling nodes and produces invalid/ambiguous MathML (e.g., base tokens plus degree token as separate children). This breaks nth-root rendering for common expressions with multi-part bases or degrees; wrap each operand in an <mrow> before appending.
Useful? React with 👍 / 👎.
| degHide?.attributes?.['m:val'] === '1' || | ||
| degHide?.attributes?.['m:val'] === 'on' || |
There was a problem hiding this comment.
Parse full ST_OnOff values for m:degHide
The hidden-degree check only treats m:val of '1' or 'on' as true, but OOXML ST_OnOff also allows tokens like 'true'; when such input appears, square roots are incorrectly emitted as <mroot> (showing an index) instead of <msqrt>. This is a format-valid input path, so the converter should normalize all accepted OnOff true values.
Useful? React with 👍 / 👎.
Made-with: Cursor
|
Hey @Abdeltoto! Thanks for this - solid work. Unfortunately #2730 landed first with the same fix, so we're closing this one |
Summary
convertRadicalconverter for them:radOMML math object type<msqrt>when the degree is hidden (m:degHide) and<mroot>when a visible degree is present (e.g. cube root)m:radPr, missingm:deg,degHidewithval=1orval=onor boolean-flag presenceFiles changed
converters/radical.ts— the converter (~35 lines)converters/index.ts— barrel exportomml-to-mathml.ts— registry registration ('m:rad': convertRadical)omml-to-mathml.test.ts— 5 test casesTest plan
pnpm test— all 40 math tests pass (5 new for radical)Note
Thank you Nick Bernal for the inspiring CS50 lecture — it motivated me to contribute to open source projects like SuperDoc.
Closes #2598