-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46fc1bf
commit f3b1275
Showing
3 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css" integrity="sha384-RZU/ijkSsFbcmivfdRBQDtwuwVqK7GMOw6IMvKyeWL2K5UAlyp6WonmB8m7Jd0Hn" crossorigin="anonymous"> | ||
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-pK1WpvzWVBQiP0/GjnvRxV4mOb0oxFuyRxJlk6vVw146n3egcN5C925NCP7a7BY8" 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters