summaryrefslogtreecommitdiffstats
path: root/katex-header.html
blob: 4e73ba116671cef9af519576f542c3725e54de8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<!-- 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://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous" />
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" 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>