-
Notifications
You must be signed in to change notification settings - Fork 5
/
katex.html
33 lines (31 loc) · 1.56 KB
/
katex.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-TEMocfGvRuD1rIAacqrknm5BQZ7W7uWitoih+jMNFXQIbNl16bO8OZmylH/Vi/Ei" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-jmxIlussZWB7qCuB+PgKG1uLjjxbVVIayPJwi6cG6Zb4YKq0JIw+OMnkkEC7kYCq" crossorigin="anonymous"></script>
<script>
"use strict";
document.addEventListener("DOMContentLoaded", function () {
var maths = document.getElementsByClassName("language-math");
for (var i=0; i<maths.length; i++) {
var el = maths[i];
katex.render(el.innerText, el, {displayMode: true});
}
var codes = document.getElementsByTagName("code");
for (i=0; i<codes.length; i++) {
el = codes[i];
if (el.classList.contains("language-math")) continue;
if (el.classList.contains("language-inline-math")) {
katex.render(el.innerText, el);
continue;
}
var parent = el.parentNode;
if (parent.nodeName.toLowerCase() === "pre") continue;
// TODO: Can this be done with DOM manipulation rather than string manipulation?
// https://stackoverflow.com/q/48438067/3019990
var inlineMath = "$" + el.outerHTML + "$";
if (parent.innerHTML.indexOf(inlineMath) !== -1) {
el.classList.add("language-inline-math");
parent.innerHTML = parent.innerHTML.replace("$" + el.outerHTML + "$", el.outerHTML);
i--;
}
}
});
</script>