-
Notifications
You must be signed in to change notification settings - Fork 15
/
jstex.d
48 lines (39 loc) · 1.48 KB
/
jstex.d
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
module adrdox.jstex;
import arsd.dom;
enum auto mathSpanCssClass = "raw-tex-math";
static immutable string[] filesForKaTeX = (){
string[] files = [];
static foreach (ext; ["css", "js"]) {
files ~= "katex.min." ~ ext;
}
static foreach (ext; ["ttf", "woff", "woff2"]) {
static foreach (family; ["AMS-Regular",
"Caligraphic-Bold", "Caligraphic-Regular",
"Fraktur-Bold", "Fraktur-Regular",
"Main-BoldItalic", "Main-Bold", "Main-Italic", "Main-Regular",
"Math-BoldItalic", "Math-Italic",
"SansSerif-Bold", "SansSerif-Italic", "SansSerif-Regular",
"Script-Regular",
"Size1-Regular", "Size2-Regular", "Size3-Regular", "Size4-Regular",
"Typewriter-Regular"]) {
files ~= "KaTeX_" ~ family ~ "." ~ ext;
}
}
return files;
}();
void prepareForKaTeX(Document document) {
auto style = Element.make("link");
style.rel = "stylesheet";
style.href = "katex.min.css";
auto head = document.getFirstElementByTagName("head");
head.addChild(style);
auto script = Element.make("script");
script.type = "text/javascript";
script.src = "katex.min.js";
script.attrs.onload = "document.querySelectorAll('span." ~ mathSpanCssClass ~ "').forEach(function(e){e.outerHTML=katex.renderToString(e.innerText)})";
auto body_ = document.getFirstElementByTagName("body");
body_.addChild(script);
}
Element mathToKaTeXHtml(string mathCode) {
return Element.make("span", mathCode, mathSpanCssClass);
}