-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdf-style.js
90 lines (83 loc) · 2.08 KB
/
sdf-style.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const styles = `
#qu-md table {
padding: 0; width: 100%; font-family: Lato, sans-serif; border-collapse: collapse;
}
#qu-md table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0;
}
#qu-md table tr:nth-child(2n) {
background-color: #004481;
}
#qu-md table tr th {
font-weight: bold;
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px;
}
#qu-md table tr td {
border: 1px solid #cccccc;
text-align: left;
margin: 0;
padding: 6px 13px;
}
#qu-md table tr th :first-child, #qu-md table tr td :first-child {
margin-top: 0;
}
#qu-md table tr th :last-child, #qu-md table tr td :last-child {
margin-bottom: 0;
}
#qu-md table tr th {
font-weight: 300;
border: 1px solid rgb(23, 73, 97);
text-align: left;
margin: 0;
padding: 6px 13px;
/*background: rgba(34,110,147,1);*/
background: #004481;
color: white;
}
`;
const ROOT_NODE = "qu-md";
function loadScript(url, callback) {
var script = document.createElement("script");
script.type = "text/javascript";
if (script.readyState) {
//IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else {
//Others
script.onload = function() {
callback();
};
}
script.src = url;
script.async = false;
document.getElementsByTagName("head")[0].appendChild(script);
}
function onDependencyLoaded(markdown) {
// manage stylesheet
const styleElement = document.createElement("style");
const styleContent = document.createTextNode(styles);
styleElement.appendChild(styleContent);
document.head.appendChild(styleElement);
// manage md
const element = document.createElement("div");
element.setAttribute("id", ROOT_NODE);
element.innerHTML = marked(markdown[0]);
document.body.appendChild(element);
}
function markdown(markdown) {
loadScript(
"https://cdn.jsdelivr.net/npm/marked/marked.min.js",
onDependencyLoaded.bind(null, markdown)
);
}