mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 06:33:55 +01:00
Move code for loading MathJax v3 into the editor core (#11433)
GitOrigin-RevId: 14adc6c35d511d6737d0f3b8c0adec00d8a0abb6
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { useRef, useEffect, type FC } from 'react'
|
import { useRef, useEffect, type FC } from 'react'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Linkify from 'react-linkify'
|
import Linkify from 'react-linkify'
|
||||||
import { loadMathJax } from '../../../../../modules/source-editor/frontend/js/utils/mathjax'
|
|
||||||
import useIsMounted from '../../../shared/hooks/use-is-mounted'
|
import useIsMounted from '../../../shared/hooks/use-is-mounted'
|
||||||
import { configureMathJax } from '../../mathjax/configure'
|
import { configureMathJax } from '../../mathjax/configure'
|
||||||
|
import { loadMathJax } from '../../mathjax/load-mathjax'
|
||||||
|
|
||||||
const MessageContent: FC<{ content: string }> = ({ content }) => {
|
const MessageContent: FC<{ content: string }> = ({ content }) => {
|
||||||
const root = useRef<HTMLDivElement | null>(null)
|
const root = useRef<HTMLDivElement | null>(null)
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import getMeta from '../../utils/meta'
|
||||||
|
|
||||||
|
let mathJaxPromise: Promise<typeof window.MathJax>
|
||||||
|
|
||||||
|
export const loadMathJax = async () => {
|
||||||
|
if (!mathJaxPromise) {
|
||||||
|
mathJaxPromise = new Promise((resolve, reject) => {
|
||||||
|
// https://docs.mathjax.org/en/v3.2-latest/upgrading/v2.html
|
||||||
|
window.MathJax = {
|
||||||
|
// https://docs.mathjax.org/en/latest/options/input/tex.html#the-configuration-block
|
||||||
|
tex: {
|
||||||
|
inlineMath: [
|
||||||
|
['\\(', '\\)'],
|
||||||
|
['$', '$'],
|
||||||
|
],
|
||||||
|
displayMath: [
|
||||||
|
['\\[', '\\]'],
|
||||||
|
['$$', '$$'],
|
||||||
|
],
|
||||||
|
packages: {
|
||||||
|
'[-]': [
|
||||||
|
'html', // avoid creating HTML elements/attributes
|
||||||
|
'require', // prevent loading disabled packages
|
||||||
|
],
|
||||||
|
},
|
||||||
|
processEscapes: true,
|
||||||
|
processEnvironments: true,
|
||||||
|
},
|
||||||
|
loader: {
|
||||||
|
load: [
|
||||||
|
'ui/safe', // https://docs.mathjax.org/en/latest/options/safe.html
|
||||||
|
],
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
enableMenu: false, // https://docs.mathjax.org/en/latest/options/menu.html
|
||||||
|
},
|
||||||
|
startup: {
|
||||||
|
typeset: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const script = document.createElement('script')
|
||||||
|
script.src = getMeta('ol-mathJax3Path')
|
||||||
|
script.addEventListener('load', async () => {
|
||||||
|
await window.MathJax.startup.promise
|
||||||
|
document.head.appendChild(window.MathJax.svgStylesheet())
|
||||||
|
resolve(window.MathJax)
|
||||||
|
})
|
||||||
|
script.addEventListener('error', reject)
|
||||||
|
document.head.append(script)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return mathJaxPromise
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user