-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
katex-header.html
24 lines (21 loc) · 1.25 KB
/
katex-header.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
<!-- Credit: https://stackoverflow.com/a/54573800 -->
<!-- Credit: https://github.com/m-ou-se/rust-horrible-katex-hack/blob/master/src/lib.rs -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-Um5gpz1odJg5Z4HAmzPtgZKdTBHZdw8S29IecapCSB31ligYPhHQZMIlWLYQGVoc" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-YNHdsYkH6gMx9y3mRkmcJ2mFUjTd0qNQQvY9VYZgQd7DcN7env35GzlmFaZ23JGp" crossorigin="anonymous"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
let codes = [...document.getElementsByTagName("code")];
for (let code of codes) {
if (code.classList.contains("language-math")) {
let p = document.createElement("p");
katex.render(code.textContent, p, { displayMode: true });
let pre = code.parentNode;
pre.parentNode.replaceChild(p, pre);
} else if (/^\$.*\$$/.test(code.textContent)) {
let span = document.createElement("span");
katex.render(code.textContent.slice(1, -1), span);
code.parentNode.replaceChild(span, code);
}
}
});
</script>