-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
17 lines (17 loc) · 804 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
onload = () => {
var main = document.getElementById("main"), contents = document.getElementById("contents");
Array.from(main.querySelectorAll("h1")).forEach(elm => {
elm.id = elm.innerText.replace(" ", "_");
var li = document.createElement("li");
li.innerHTML = `<a href="#${elm.id}">${elm.innerText}</a>`;
contents.appendChild(li);
});
Array.from(main.querySelectorAll("h2")).forEach(elm => {
var previousSibling = elm.previousSibling;
while (previousSibling && previousSibling.nodeName.toLowerCase() != "h1") {
previousSibling = previousSibling.previousSibling;
}
elm.id = previousSibling.id + "." + elm.innerText.substring(0, Math.min(elm.innerText.indexOf(" "), elm.innerText.indexOf(":")));
})
Array.from(main.querySelectorAll("pre, code")).forEach(hljs.highlightElement);
}