PluginProbe
Gutenberg / 22.3.0
Gutenberg v22.3.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / mathml-kses.php

mathml-kses.php in Gutenberg 22.3.0, at lib/mathml-kses.php

199 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add MathML elements and attributes to wp_kses_allowed_html.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Add MathML elements to the allowed tags array.
10 *
11 * This enables MathML content (e.g. converted from LaTeX, but also directly
12 * imported or pasted) to pass through WordPress's content sanitization.
13 *
14 * @param array $allowedtags The allowed tags.
15 *
16 * @return array The allowed tags with MathML elements added.
17 */
18 function gutenberg_kses_allow_mathml( $allowedtags ) {
19 // https://www.w3.org/TR/mathml-core/#global-attributes
20 // Except common attributes added by _wp_add_global_attributes.
21 $math_global_attributes = array(
22 'displaystyle' => true,
23 'scriptlevel' => true,
24 'mathbackground' => true,
25 'mathcolor' => true,
26 'mathsize' => true,
27 // Common attributes also defined by _wp_add_global_attributes.
28 // We do not want to add all those global attributes though.
29 'class' => true,
30 'data-*' => true,
31 'dir' => true,
32 'id' => true,
33 'style' => true,
34 );
35
36 $math_overunder_attributes = array(
37 'accentunder' => true,
38 'accent' => true,
39 );
40
41 return array_merge(
42 $allowedtags,
43 array(
44 // https://www.w3.org/TR/mathml-core/#the-top-level-math-element
45 'math' => array_merge(
46 $math_global_attributes,
47 array(
48 'display' => true,
49 )
50 ),
51
52 // https://www.w3.org/TR/mathml-core/#token-elements
53 // https://www.w3.org/TR/mathml-core/#text-mtext
54 'mtext' => $math_global_attributes,
55 // https://www.w3.org/TR/mathml-core/#the-mi-element
56 'mi' => array_merge(
57 $math_global_attributes,
58 array(
59 'mathvariant' => true,
60 )
61 ),
62 // https://www.w3.org/TR/mathml-core/#number-mn
63 'mn' => $math_global_attributes,
64 // https://www.w3.org/TR/mathml-core/#operator-fence-separator-or-accent-mo
65 'mo' => array_merge(
66 $math_global_attributes,
67 array(
68 'form' => true,
69 'fence' => true,
70 'separator' => true,
71 'lspace' => true,
72 'rspace' => true,
73 'stretchy' => true,
74 'symmetric' => true,
75 'maxsize' => true,
76 'minsize' => true,
77 'largeop' => true,
78 'movablelimits' => true,
79 )
80 ),
81 // https://www.w3.org/TR/mathml-core/#space-mspace
82 'mspace' => array_merge(
83 $math_global_attributes,
84 array(
85 'width' => true,
86 'height' => true,
87 'depth' => true,
88 )
89 ),
90 // https://www.w3.org/TR/mathml-core/#string-literal-ms
91 'ms' => $math_global_attributes,
92
93 // https://www.w3.org/TR/mathml-core/#general-layout-schemata
94 // https://www.w3.org/TR/mathml-core/#horizontally-group-sub-expressions-mrow
95 'mrow' => $math_global_attributes,
96 // https://www.w3.org/TR/mathml-core/#fractions-mfrac
97 'mfrac' => array_merge(
98 $math_global_attributes,
99 array(
100 'linethickness' => true,
101 )
102 ),
103 // https://www.w3.org/TR/mathml-core/#radicals-msqrt-mroot
104 'msqrt' => $math_global_attributes,
105 'mroot' => $math_global_attributes,
106 // https://www.w3.org/TR/mathml-core/#style-change-mstyle
107 'mstyle' => $math_global_attributes,
108 // https://www.w3.org/TR/mathml-core/#error-message-merror
109 'merror' => $math_global_attributes,
110 // https://www.w3.org/TR/mathml-core/#adjust-space-around-content-mpadded
111 'mpadded' => array_merge(
112 $math_global_attributes,
113 array(
114 'width' => true,
115 'height' => true,
116 'depth' => true,
117 'lspace' => true,
118 'voffset' => true,
119 )
120 ),
121 // https://www.w3.org/TR/mathml-core/#making-sub-expressions-invisible-mphantom
122 'mphantom' => $math_global_attributes,
123
124 // https://www.w3.org/TR/mathml-core/#script-and-limit-schemata
125 // https://www.w3.org/TR/mathml-core/#subscripts-and-superscripts-msub-msup-msubsup
126 'msub' => $math_global_attributes,
127 'msup' => $math_global_attributes,
128 'msubsup' => $math_global_attributes,
129 // https://www.w3.org/TR/mathml-core/#underscripts-and-overscripts-munder-mover-munderover
130 'munder' => array_merge( $math_global_attributes, $math_overunder_attributes ),
131 'mover' => array_merge( $math_global_attributes, $math_overunder_attributes ),
132 'munderover' => array_merge( $math_global_attributes, $math_overunder_attributes ),
133 // https://www.w3.org/TR/mathml-core/#prescripts-and-tensor-indices-mmultiscripts
134 'mmultiscripts' => $math_global_attributes,
135 'mprescripts' => $math_global_attributes,
136
137 // https://www.w3.org/TR/mathml-core/#tabular-math
138 // https://www.w3.org/TR/mathml-core/#table-or-matrix-mtable
139 'mtable' => array_merge(
140 $math_global_attributes,
141 array(
142 // Non-standard, used by temml/katex.
143 // https://developer.mozilla.org/en-US/docs/Web/MathML/Reference/Element/mtable
144 'columnalign' => true,
145 'rowspacing' => true,
146 'columnspacing' => true,
147 'align' => true,
148 'rowalign' => true,
149 'columnlines' => true,
150 'rowlines' => true,
151 'frame' => true,
152 'framespacing' => true,
153 'width' => true,
154 )
155 ),
156 // https://www.w3.org/TR/mathml-core/#row-in-table-or-matrix-mtr
157 'mtr' => array_merge(
158 $math_global_attributes,
159 array(
160 // Non-standard, used by temml/katex.
161 // https://developer.mozilla.org/en-US/docs/Web/MathML/Reference/Element/mtr
162 'columnalign' => true,
163 'rowalign' => true,
164 )
165 ),
166 // https://www.w3.org/TR/mathml-core/#entry-in-table-or-matrix-mtd
167 'mtd' => array_merge(
168 $math_global_attributes,
169 array(
170 'columnspan' => true,
171 'rowspan' => true,
172 // Non-standard, used by temml/katex.
173 // https://developer.mozilla.org/en-US/docs/Web/MathML/Reference/Element/mtd
174 'columnalign' => true,
175 'rowalign' => true,
176 )
177 ),
178
179 // https://www.w3.org/TR/mathml-core/#semantics-and-presentation
180 'semantics' => $math_global_attributes,
181 'annotation' => array_merge(
182 $math_global_attributes,
183 array(
184 'encoding' => true,
185 )
186 ),
187
188 // Non-standard but widely supported, used by temml/katex.
189 'menclose' => array_merge(
190 $math_global_attributes,
191 array(
192 'notation' => true,
193 )
194 ),
195 )
196 );
197 }
198 add_filter( 'wp_kses_allowed_html', 'gutenberg_kses_allow_mathml' );
199