-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkatex.html
More file actions
44 lines (43 loc) · 2.13 KB
/
Copy pathkatex.html
File metadata and controls
44 lines (43 loc) · 2.13 KB
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
40
41
42
43
44
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.18.1/dist/katex.min.css" integrity="sha384-1vdNCNel6Tx/NQa8IR1mGOGKsbGreCkOPfbtPPnUURJ5Tu2PRVfQ/7KLZC+Pi1p1" crossorigin="anonymous">
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.18.1/dist/katex.min.js" integrity="sha384-ycJ6GAwiS15LoUPipwJOrWTvkUHl/YqELValBwI5I4awP1EeEQJYarj+w85ntcz7" crossorigin="anonymous"></script>
<!-- From: https://github.com/rust-lang/rust/pull/95691#issuecomment-1089080597 -->
<script>
document.addEventListener("DOMContentLoaded", function () {
// Make a list of all replacements to make. Otherwise, the for loops
// fail to iterate over all elements that need to be replaced.
let to_do = [];
// Render
// ```math
// equation
// ```
// blocks as display mode equations with katex. Markdown translates this to
// <pre class="language-math"><code>equation</code></pre>
for (let e of document.getElementsByTagName('pre')) {
if (e.classList.contains('language-math')) {
to_do.push(function () {
let x = document.createElement('p');
katex.render(e.innerText, x, {displayMode: true, throwOnError: false});
e.parentNode.parentNode.replaceChild(x, e.parentNode);
});
}
}
// Render $`equation`$ elements as inline equations with katex. Markdown
// translates this to <p>...$<code>equation</code>$...</p>. Also remove the
// extra $ characters.
// <pre class="language-math"><code>equation</code></pre>
for (let e of document.getElementsByTagName('code')) {
let n = e.nextSibling; let p = e.previousSibling;
if (n && p && /^\$/.test(n.data) && /\$$/.test(p.data)) {
to_do.push(function () {
let n = e.nextSibling; let p = e.previousSibling;
let x = document.createElement('span');
katex.render(e.innerText, x, {throwOnError: false});
e.parentNode.replaceChild(x, e);
n.splitText(1); n.remove();
p.splitText(p.data.length - 1).remove();
});
}
}
for (let f of to_do) f();
});
</script>