summaryrefslogtreecommitdiffstats
path: root/katex-header.html
diff options
context:
space:
mode:
Diffstat (limited to 'katex-header.html')
-rw-r--r--katex-header.html22
1 files changed, 22 insertions, 0 deletions
diff --git a/katex-header.html b/katex-header.html
new file mode 100644
index 0000000..4e73ba1
--- /dev/null
+++ b/katex-header.html
@@ -0,0 +1,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>