Эх сурвалжийг харах

Improve MathJax filtering of font-family attribute (#18819)

GitOrigin-RevId: 04460c9549c33dbf76efba0e72bed8694072de9d
Alf Eaton 2 жил өмнө
parent
commit
4971afd527

+ 13 - 1
services/web/frontend/js/features/mathjax/load-mathjax.ts

@@ -40,7 +40,6 @@ export const loadMathJax = async (options?: {
             '[-]': [
               'html', // avoid creating HTML elements/attributes
               'require', // prevent loading disabled packages
-              'unicode', // Prevent CSS injection https://github.com/mathjax/MathJax/issues/3129 / https://github.com/mathjax/MathJax/issues/3241
             ],
           },
           processEscapes: true,
@@ -65,6 +64,19 @@ export const loadMathJax = async (options?: {
               .findID('Renderer')
               .disable()
           },
+          ready() {
+            window.MathJax.startup.defaultReady()
+
+            // remove anything from the "font-family" attribute after a semicolon
+            // so it's not added to the style attribute
+            // https://github.com/mathjax/MathJax/issues/3129#issuecomment-1807225345
+            const { safe } = window.MathJax.startup.document
+            safe.filterAttributes.set('fontfamily', 'filterFontFamily')
+            safe.filterMethods.filterFontFamily = (
+              _safe: any,
+              family: string
+            ) => family.split(/;/)[0]
+          },
         },
       }