From f048e0cf1bc7a2ca4c415bb29ae80bdea13d1d4b Mon Sep 17 00:00:00 2001 From: Calvin Lee Date: Mon, 25 Nov 2024 23:18:52 +0000 Subject: [PATCH] Allow MathML core tags in sanitized content --- config/config.exs | 1 + priv/scrubbers/default.ex | 113 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/config/config.exs b/config/config.exs index e919910b3..bca7211d5 100644 --- a/config/config.exs +++ b/config/config.exs @@ -302,6 +302,7 @@ allow_headings: false, allow_tables: false, allow_fonts: false, + allow_math: true, scrub_policy: [ Pleroma.HTML.Scrubber.Default, Pleroma.HTML.Transform.MediaProxy diff --git a/priv/scrubbers/default.ex b/priv/scrubbers/default.ex index 74de910fd..96473203e 100644 --- a/priv/scrubbers/default.ex +++ b/priv/scrubbers/default.ex @@ -124,6 +124,119 @@ defmodule Pleroma.HTML.Scrubber.Default do Meta.allow_tag_with_these_attributes(:font, ["face"]) end + if Pleroma.Config.get!([:markup, :allow_math]) do + Meta.allow_tag_with_these_attributes("annotation", ["encoding"]) + Meta.allow_tag_with_these_attributes(:"annotation-xml", ["encoding"]) + + Meta.allow_tag_with_these_attributes(:math, [ + "display", + "displaystyle", + "mathvariant", + "scriptlevel" + ]) + + basic_math_tags = [ + "maction", + "merror", + :mi, + "mmultiscripts", + :mn, + "mphantom", + "mprescripts", + "mroot", + "mrow", + "ms", + "msqrt", + "mstyle", + "msub", + "msubsup", + "msup", + "mtable", + "mtext", + "mtr", + "semantics" + ] + + for tag <- basic_math_tags do + Meta.allow_tag_with_these_attributes(unquote(tag), [ + "mathvariant", + "displaystyle", + "scriptlevel" + ]) + end + + Meta.allow_tag_with_these_attributes("mfrac", [ + "displaystyle", + "linethickness", + "mathvariant", + "scriptlevel" + ]) + + Meta.allow_tag_with_these_attributes(:mo, [ + "displaystyle", + "form", + "largeop", + "lspace", + "mathvariant", + "minsize", + "movablelimits", + "rspace", + "scriptlevel", + "stretchy", + "symmetric" + ]) + + Meta.allow_tag_with_these_attributes("mover", [ + "accent", + "displaystyle", + "mathvariant", + "scriptlevel" + ]) + + Meta.allow_tag_with_these_attributes("mpadded", [ + "depth", + "displaystyle", + "height", + "lspace", + "mathvariant", + "scriptlevel", + "voffset", + "width" + ]) + + Meta.allow_tag_with_these_attributes("mspace", [ + "depth", + "displaystyle", + "height", + "mathvariant", + "scriptlevel", + "width" + ]) + + Meta.allow_tag_with_these_attributes("mtd", [ + "columnspan", + "displaystyle", + "mathvariant", + "rowspan", + "scriptlevel" + ]) + + Meta.allow_tag_with_these_attributes("munder", [ + "accentunder", + "displaystyle", + "mathvariant", + "scriptlevel" + ]) + + Meta.allow_tag_with_these_attributes("munderover", [ + "accent", + "accentunder", + "displaystyle", + "mathvariant", + "scriptlevel" + ]) + end + Meta.allow_tag_with_these_attributes(:center, []) Meta.allow_tag_with_these_attributes(:small, [])