PHP HTML 净化器和 MathML

PHP HTML Purifier and MathML

有没有什么简单的方法可以让 HTML Purifier 中的所有 MathML 标签都带有属性?

我试图将 https://developer.mozilla.org/en-US/docs/Web/MathML/Element/semantics 中所有带有属性的 MathML 标签放入 HTML.Allowed 但我不知道这是否正确。

HTML Purifier 目前没有对 MathML 的原生支持。有一个旧的拉取请求,您可以重新利用 here, but as it's a few years old patching it in will almost surely require significant manual effort; see also some discussion here:

The primary consideration is security. When adding a very big new extension like MathML, it is very tempting to cut corners, and not truly understand every corner of the specification and build a parser that truly understands what it reads, and isn't just checking syntax blindly.

或者,您可以使用 customization guide 将它们作为新标签和属性添加到 HTML Purifier,但这是更多的工作,而不是更少。

简单地将标签添加到 HTML.Allowed 不会有太大作用 - HTML Purifier 的优势在于它了解标签出现的上下文、允许出现的位置以及限制感知它们的属性(例如 'width' 这样的属性采用整数,但是 'style' 这样的属性采用 CSS (将单独清理),而 'onclick' 这样的属性是不安全的定义)。如果 HTML Purifier 对特定标签一无所知,它不会允许它,即使您将它添加到白名单,因为它不知道如何实际处理该标签。

简而言之:

不,不幸的是,没有简单的方法可以在 HTML Purifier 中使用 MathML。