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

GitOrigin-RevId: 04460c9549c33dbf76efba0e72bed8694072de9d
This commit is contained in:
Alf Eaton 2024-06-11 09:34:50 +01:00 committed by Copybot
parent d3c270369d
commit 4971afd527

View file

@ -40,7 +40,6 @@ export const loadMathJax = async (options?: {
'[-]': [ '[-]': [
'html', // avoid creating HTML elements/attributes 'html', // avoid creating HTML elements/attributes
'require', // prevent loading disabled packages '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, processEscapes: true,
@ -65,6 +64,19 @@ export const loadMathJax = async (options?: {
.findID('Renderer') .findID('Renderer')
.disable() .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]
},
}, },
} }