overleaf/services/web/cypress/support/shared/commands/mathjax.ts
Alf Eaton c997d1dc2b Remove MathJax v2 (#16961)
GitOrigin-RevId: 32a43361cfc883aa1a5ed85f6be5432b6e838b9d
2024-02-09 09:06:42 +00:00

32 lines
943 B
TypeScript

const MATHJAX_STUB = `
window.MathJax = {
startup: {
promise: Promise.resolve()
},
svgStylesheet: () => document.createElement("STYLE"),
typesetPromise: (elements) => {
for (const element of elements) {
// This will keep math delimeters around the text
element.classList.add('MathJax')
}
return Promise.resolve()
},
tex2svgPromise: (content) => {
const text = document.createElement('SPAN')
text.classList.add('MathJax')
text.innerText = content
return Promise.resolve(text)
},
getMetricsFor: () => ({}),
texReset: () => {},
}
`
export const interceptMathJax = () => {
// NOTE: this is just a URL to be intercepted with the stub, not the real (versioned) MathJax URL
const url = '/js/libs/mathjax/es5/tex-svg-full.js'
cy.window().then(win => {
win.metaAttributesCache.set('ol-mathJaxPath', url)
})
cy.intercept('GET', url, MATHJAX_STUB).as('mathjax-load-request')
}