MCPcopy Create free account
hub / github.com/Hashnode/starter-kit / handleMathJax

Function handleMathJax

packages/utils/handle-math-jax.js:1–27  ·  view source on GitHub ↗
(rerun = false)

Source from the content-addressed store, hash-verified

1const handleMathJax = (rerun = false) => {
2 if (typeof window === 'undefined') {
3 return;
4 }
5
6 const mathjaxScript = 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js';
7 if (!window.MathJax) {
8 window.MathJax = {
9 tex: {
10 inlineMath: [['\\(', '\\)']],
11 },
12 };
13 }
14
15 let mathjaxScriptTag = document.querySelector(`script[src="${mathjaxScript}"]`);
16 if (!mathjaxScriptTag) {
17 let script = document.createElement('script');
18 script.type = 'text/javascript';
19 script.src = mathjaxScript;
20 script.onload = function () {
21 window.MathJax && 'mathml2chtml' in window.MathJax && window.MathJax.mathml2chtml();
22 };
23 document.head.appendChild(script);
24 } else if (rerun) {
25 window.MathJax && 'mathml2chtml' in window.MathJax && window.MathJax.mathml2chtml();
26 }
27};
28
29export default handleMathJax;
30

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected