You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
751 B

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