| 1 |
export default (className, mode) => { |
| 2 |
if (mode === 'katex') { |
| 3 |
const maths = document.querySelectorAll(`.${className}`) |
| 4 |
|
| 5 |
for (let i = 0; i < maths.length; i++) { |
| 6 |
const tex = maths[i].textContent || maths[i].innerText |
| 7 |
|
| 8 |
if (tex.startsWith('\\(') && tex.endsWith('\\)')) { |
| 9 |
katex.render(tex.slice(2, -2), maths[i], {'displayMode': false}) |
| 10 |
} else if (tex.startsWith('\\[') && tex.endsWith('\\]')) { |
| 11 |
katex.render(tex.slice(2, -2), maths[i], {'displayMode': true}) |
| 12 |
} |
| 13 |
} |
| 14 |
} else if (mode === 'mathjax') { |
| 15 |
if (typeof MathJax.startup.output.clearCache !== "undefined") { |
| 16 |
MathJax.startup.output.clearCache() |
| 17 |
} |
| 18 |
MathJax.typesetClear() |
| 19 |
MathJax.texReset() |
| 20 |
MathJax.typesetPromise() |
| 21 |
} |
| 22 |
} |