mathjax.ts 938 B

1234567891011121314151617181920212223242526272829303132
  1. const MATHJAX_STUB = `
  2. window.MathJax = {
  3. startup: {
  4. promise: Promise.resolve()
  5. },
  6. svgStylesheet: () => document.createElement("STYLE"),
  7. typesetPromise: (elements) => {
  8. for (const element of elements) {
  9. // This will keep math delimeters around the text
  10. element.classList.add('MathJax')
  11. }
  12. return Promise.resolve()
  13. },
  14. tex2svgPromise: (content) => {
  15. const text = document.createElement('SPAN')
  16. text.classList.add('MathJax')
  17. text.innerText = content
  18. return Promise.resolve(text)
  19. },
  20. getMetricsFor: () => ({}),
  21. texReset: () => {},
  22. }
  23. `
  24. export const interceptMathJax = () => {
  25. // NOTE: this is just a URL to be intercepted with the stub, not the real (versioned) MathJax URL
  26. const url = '/js/libs/mathjax/es5/tex-svg.js'
  27. cy.window().then(win => {
  28. win.metaAttributesCache.set('ol-mathJaxPath', url)
  29. })
  30. cy.intercept('GET', url, MATHJAX_STUB).as('mathjax-load-request')
  31. }