Mercurial > repos > public > wdown
comparison katex/contrib/mathtex-script-type.mjs @ 8:4a25b534c81c javascript-experiment
Add v8 engine and include katex
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 17 Jun 2020 21:43:52 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
7:a5aa39557726 | 8:4a25b534c81c |
---|---|
1 import katex from '../katex.mjs'; | |
2 | |
3 let scripts = document.body.getElementsByTagName("script"); | |
4 scripts = Array.prototype.slice.call(scripts); | |
5 scripts.forEach(function (script) { | |
6 if (!script.type || !script.type.match(/math\/tex/i)) { | |
7 return -1; | |
8 } | |
9 | |
10 const display = script.type.match(/mode\s*=\s*display(;|\s|\n|$)/) != null; | |
11 const 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 }); |