Skip to content

fix(ui): preserve SVG tags in DOMPurify config for KaTeX math rendering#25866

Merged
Brendonovich merged 1 commit intoanomalyco:devfrom
zharinov:zharinov/dopurify-katex-svg
May 6, 2026
Merged

fix(ui): preserve SVG tags in DOMPurify config for KaTeX math rendering#25866
Brendonovich merged 1 commit intoanomalyco:devfrom
zharinov:zharinov/dopurify-katex-svg

Conversation

@zharinov
Copy link
Copy Markdown
Contributor

@zharinov zharinov commented May 5, 2026

Issue for this PR

Closes #25812

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

DOMPurify was stripping <svg> and <path> elements from KaTeX-rendered HTML. KaTeX renders \sqrt, \overrightarrow, \widehat, \widetilde, \overbrace, \underbrace as inline SVG — these were silently removed during sanitization, leaving the radicand visible but the radical symbol missing.

Added ADD_TAGS: ["svg", "path"] and the necessary SVG attributes (d, viewBox, preserveAspectRatio, xmlns) to the DOMPurify config.

How did you verify your code works?

Tested in desktop dev build:

$$\sqrt{x^2 + y^2}$$ $$\sqrt[4]{a^3 + b^3}$$ $$F(t) = \sqrt{t + 1} + \sqrt[7]{t^2 - 9}$$ $$\overrightarrow{AB}$$ $$\widehat{XYZ}$$ $$\widetilde{f(x)}$$ $$\overbrace{x_1 + x_2 + \cdots + x_n}^{n\text{ terms}}$$ $$\underbrace{a + a + \cdots + a}_{m\text{ times}}$$

All render correctly. DOMPurify still strips event handlers on SVG elements.

Screenshots / recordings

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@zharinov
Copy link
Copy Markdown
Contributor Author

zharinov commented May 5, 2026

image

@Brendonovich Brendonovich merged commit 518503b into anomalyco:dev May 6, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web GUI doesn't render latex square root symbol

2 participants