`SafeHTML` removes the MathML `<none>` element, which moves scripts in `mmultiscripts`
❌ This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Target branch: release-v0.20.x
Observed behavior
SafeHTML removes <none> from MathML. In mmultiscripts, <none> fills an empty script slot, so the script after it moves into that slot.
Input:
<math><mmultiscripts><mi>C</mi><mprescripts/><none/><mn>14</mn></mmultiscripts></math>
DOM that SafeHTML renders:
<math class="safe-html"><mmultiscripts class="safe-html"><mi class="safe-html">C</mi><mprescripts class="safe-html"></mprescripts><mn class="safe-html">14</mn></mmultiscripts></math>
On the MathJax path for browsers without native MathML, 14 renders as a left subscript of C.
DOMPurify 3.4.17 leaves none out of its default MathML tags, and ADD_TAGS adds only object and semantics.
Expected behavior
SafeHTML keeps <none>, so each script stays in its slot.
User-facing consequences
A learner reads a wrong formula. For example, the mass number of an isotope shows where the atomic number belongs.
Steps to reproduce
- Render the default export of
packages/kolibri-common/components/SafeHTMLwith the input above as itshtmlprop. - Inspect the rendered
mmultiscriptselement.
Context
- Kolibri
developat 758605b764 - Jest with jsdom
- #15598 sends MathJax's TeX output through
SafeHTML. MathJax writes<none>for\prescript{14}{}{C}and\sideset{^a}{}{\sum}.
Acceptance Criteria
- [ ] For the input above, the
mmultiscriptsthatSafeHTMLrenders has<none>between<mprescripts>and<mn>14</mn>. - [ ] On the MathJax path, 14 renders as a left superscript of C.
- [ ] A
SafeHTMLtest covers the input above.
AI usage
Claude Code found this during the self-review of #15598, reproduced it in Jest and drafted this issue.
Plan: SafeHTML keeps <none> inside mmultiscripts, so each script stays in its slot (#16009).
- [ ] Keep
<none>through sanitisation - [ ] Self-review the produced code
Assumptions — the issue did not settle these; say so if one is wrong.
- A
<none>that is not a direct child ofmmultiscripts(top level, inmsub, in anmrowinsidemmultiscripts) falls back to native math on the MathJax path, as a misplacedmprescriptsdoes. Today it is stripped and MathJax renders the expression, so those inputs lose MathJax output on Chromium < 109. If they should keep it, anuponSanitizeElementhook must strip<none>whose parent is notmmultiscripts, and the misplaced-<none>test row inverts. - Only
nonejoins the allowlist; ifmaction,annotationor themstackfamily should render too, each needs its own entry and test. - A Jest assertion on MathJax's output structure meets the left-superscript criterion; if a rendered capture is required, QA must force the MathJax path in a browser.
Written by rtibblesbot, an LLM-based coding agent.
Fixed in #16024