Add patches to accept MathML

This commit is contained in:
Oneric 2024-10-03 21:17:09 +02:00
parent ad3a2c49ba
commit e89f927929
2 changed files with 148 additions and 0 deletions

View file

@ -0,0 +1,146 @@
From 1cf33a318de09b2624c8d92b635d710379ac7ef8 Mon Sep 17 00:00:00 2001
From: Calvin Lee <pounce@integraldoma.in>
Date: Sat, 16 Sep 2023 21:33:33 +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..0cc0f2577 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -302,6 +302,7 @@ config :pleroma, :markup,
allow_headings: false,
allow_tables: false,
allow_fonts: false,
+ allow_math: false,
scrub_policy: [
Pleroma.HTML.Scrubber.Default,
Pleroma.HTML.Transform.MediaProxy
diff --git a/priv/scrubbers/default.ex b/priv/scrubbers/default.ex
index 74de910fd..2eba385dd 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, [])

View file

@ -9,3 +9,5 @@ pr814_07_fix-bmp-metadata-handling.patch
pr814_08_federation-with-multi-ld-profiles.patch
pr814_09_fix-multi-selection-poll-counts.patch
pr814_10_fix-swagger-ui.patch
# Preserve math markup from other instances
pr642_receive-mathml.patch