-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
50 lines (44 loc) · 1.26 KB
/
renderer.js
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
45
46
47
48
49
50
"use strict";
let library_loaded = 0;
let library_needed = 0;
function addSyntaxHighlight() {
let languages = []
for (let code of $('pre>code')) {
if (code.className === "") {
code.className = "language-plaintext"
} else {
languages.push(code.className.split("-")[1]);
}
}
if (languages.length > 0) {
library_needed = languages.length + 1;
addscripts('https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/highlight.min.js', () => {
for (let lang of languages) {
if (globalThis.hljs.getLanguage(lang) === undefined) {
addscripts(`https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.7.0/build/languages/${lang}.min.js`, () => {
library_loaded += 1;
if (library_loaded === library_loaded) {
globalThis.hljs.highlightAll();
}
})
}
}
});
}
}
function addscripts(url, callback) {
let js = document.createElement("script");
js.src = url;
js.async = true;
js.defer = false;
js.onload = callback;
document.head.appendChild(js);
}
async function render() {
renderable = false;
globalThis.renderMathInElement(document.body);
addSyntaxHighlight();
}
if (typeof renderable !== "undefined" && renderable) {
render();
}