-
Notifications
You must be signed in to change notification settings - Fork 6
/
autoindex_strapdown.js
38 lines (31 loc) · 1.51 KB
/
autoindex_strapdown.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
document.addEventListener('DOMContentLoaded', function() {
var b = document.body, xmp, strapdown;
// Hide the page while eviscerating it.
b.style.display = 'none';
// Set the title, if not empty.
if (conf.title) document.title += ' - ' + conf.title;
// Create a script element to fetch Strapdown.js.
strapdown = document.createElement('script');
strapdown.setAttribute('src', conf.strapdown ? conf.strapdown : 'https://ais.habilis.net/strapdown/v/0.2/strapdown.js');
// Create an XMP element for Strapdown.js to process.
xmp = document.createElement('xmp'),
xmp.setAttribute('theme', conf.theme);
// Loop through the body elements, accumulating text or HTML in the XMP.
// Mod_autoindex includes the HEADER/README as childless PRE-blocks, so they
// are accumulated as text. All other elements are accumulated as HTML.
//
// The reason to make the distinction between PRE-blocks with and without children
// is because mod_autoindex's FancyIndexing option generates the index inside a PRE.
// The FancyIndex PRE-blocks have many child elements, but HEADER/README PRE-blocks
// will have no child elements.
for (var c=b.children, i=0; i < c.length; i++) {
var e = c[i],
t = (e.nodeName == 'PRE' && e.children.length == 0) ? e.textContent : e.outerHTML;
xmp.innerHTML += t + '\n\n';
}
// Now that everything is copied into the XMP, clear the body.
while (b.lastChild) { b.removeChild(b.lastChild); }
// Insert the XMP and load Strapdown.js to render it.
b.appendChild(xmp);
b.appendChild(strapdown);
});