arnaucube
arnaucube/arnaucube.comPublic Self-hosted repository
arnaucube.com/blogo-input/js/katex/contrib/mathtex-script-type.mjs
blogo-input/js/katex/contrib/mathtex-script-type.mjsRaw
 1import katex from '../katex.mjs';
 2
 3var scripts = document.body.getElementsByTagName("script");
 4scripts = Array.prototype.slice.call(scripts);
 5scripts.forEach(function (script) {
 6  if (!script.type || !script.type.match(/math\/tex/i)) {
 7    return -1;
 8  }
 9
10  var display = script.type.match(/mode\s*=\s*display(;|\s|\n|$)/) != null;
11  var katexElement = document.createElement(display ? "div" : "span");
12  katexElement.setAttribute("class", display ? "equation" : "inline-equation");
13
14  try {
15    katex.render(script.text, katexElement, {
16      displayMode: display
17    });
18  } catch (err) {
19    //console.error(err); linter doesn't like this
20    katexElement.textContent = script.text;
21  }
22
23  script.parentNode.replaceChild(katexElement, script);
24});