-
Notifications
You must be signed in to change notification settings - Fork 2
/
404.js
26 lines (26 loc) · 1.21 KB
/
404.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
(function() {
/* get the base64 hash from the url */
var hash = window.location.pathname.substring(1);
/* decode the hash into text */
var content = decodeURIComponent(escape(LZString.decompressFromBase64(hash)));
/* split into math and markdown segments */
var contents = content.split('$$');
if (contents.length === 1) {
/* if there is no math, process it with marked and replace text in content div */
document.getElementById('content').innerHTML = DOMPurify.sanitize(marked.parse(content));
} else {
/* load MathJaX only when needed */
const jaxTag = document.createElement('script');
jaxTag.src = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js";
jaxTag.async = true;
document.body.appendChild(jaxTag);
/* process only even indices with marked so that math is untouched */
for (let index = 0; index < contents.length; index++) {
if (index % 2 === 0) {
contents[index] = marked.parse(contents[index]);
};
};
/* join again and replace text in content div */
document.getElementById('content').innerHTML = DOMPurify.sanitize(contents.join('$$'));
};
}());