From 4971afd5275726a0045673fc6de168271ef8edf5 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Tue, 11 Jun 2024 09:34:50 +0100 Subject: [PATCH] Improve MathJax filtering of font-family attribute (#18819) GitOrigin-RevId: 04460c9549c33dbf76efba0e72bed8694072de9d --- .../frontend/js/features/mathjax/load-mathjax.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/services/web/frontend/js/features/mathjax/load-mathjax.ts b/services/web/frontend/js/features/mathjax/load-mathjax.ts index 4d529f2fa4..0d9153ba56 100644 --- a/services/web/frontend/js/features/mathjax/load-mathjax.ts +++ b/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] + }, }, }