-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkatex.html
39 lines (35 loc) · 1.98 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
34
35
36
37
38
39
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous">
<!-- The loading of KaTeX is deferred to speed up page rendering -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script>
<!-- To automatically render math in text elements, include the auto-render extension: -->
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></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>