lib
block-supports
4 months ago
compat
3 months ago
experimental
3 months ago
media
3 months ago
README.md
10.0 KB
7 months ago
block-editor-settings.php
5.4 KB
7 months ago
block-template-utils.php
3.5 KB
1 year ago
blocks.php
11.8 KB
7 months ago
class-wp-duotone-gutenberg.php
37.6 KB
5 months ago
class-wp-icons-registry-gutenberg.php
7.1 KB
4 months ago
class-wp-rest-edit-site-export-controller-gutenberg.php
1.2 KB
2 years ago
class-wp-rest-global-styles-controller-gutenberg.php
24.5 KB
7 months ago
class-wp-rest-icons-controller-gutenberg.php
481 B
4 months ago
class-wp-theme-json-data-gutenberg.php
1.7 KB
2 years ago
class-wp-theme-json-gutenberg.php
196.1 KB
3 months ago
class-wp-theme-json-resolver-gutenberg.php
34.7 KB
6 months ago
class-wp-theme-json-schema-gutenberg.php
7.4 KB
7 months ago
client-assets.php
16.4 KB
4 months ago
demo.php
1.6 KB
1 year ago
global-styles-and-settings.php
14.2 KB
7 months ago
init.php
945 B
4 months ago
interactivity-api.php
1.2 KB
7 months ago
load.php
10.9 KB
3 months ago
mathml-kses.php
6.3 KB
10 months ago
overlay-patterns.php
12.2 KB
6 months ago
remove-core-enqueue-scripts.php
779 B
5 months ago
rest-api.php
1.6 KB
4 months ago
script-loader.php
5.9 KB
5 months ago
theme-i18n.json
1.8 KB
7 months ago
theme.json
9.2 KB
5 months ago
upgrade.php
2.6 KB
5 months ago
| 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 |