1 |
document.addEventListener('DOMContentLoaded', function() { |
2 |
var b = document.body, xmp, strapdown; |
3 |
|
4 |
// Hide the page while eviscerating it. |
5 |
b.style.display = 'none'; |
6 |
|
7 |
// Set the title, if not empty. |
8 |
if (conf.title) document.title += ' - ' + conf.title; |
9 |
|
10 |
// Create a script element to fetch Strapdown.js. |
11 |
strapdown = document.createElement('script'); |
12 |
// strapdown.setAttribute('src', conf.strapdown ? conf.strapdown : 'http://strapdownjs.com/v/0.2/strapdown.js'); |
13 |
strapdown.setAttribute('src', conf.strapdown ? conf.strapdown : 'https://cdn.jsdelivr.net/gh/Naereen/StrapDown.js@master/strapdown.min.js'); |
14 |
|
15 |
|
16 |
// Create an XMP element for Strapdown.js to process. |
17 |
xmp = document.createElement('xmp'), |
18 |
xmp.setAttribute('theme', conf.theme); |
19 |
|
20 |
// Loop through the body elements, accumulating text or HTML in the XMP. |
21 |
// Mod_autoindex includes the HEADER/README as childless PRE-blocks, so they |
22 |
// are accumulated as text. All other elements are accumulated as HTML. |
23 |
// |
24 |
// The reason to make the distinction between PRE-blocks with and without children |
25 |
// is because mod_autoindex's FancyIndexing option generates the index inside a PRE. |
26 |
// The FancyIndex PRE-blocks have many child elements, but HEADER/README PRE-blocks |
27 |
// will have no child elements. |
28 |
for (var c=b.children, i=0; i < c.length; i++) { |
29 |
var e = c[i], |
30 |
t = (e.nodeName == 'PRE' && e.children.length == 0) ? e.textContent : e.outerHTML; |
31 |
xmp.innerHTML += t + '\n\n'; |
32 |
} |
33 |
|
34 |
// Now that everything is copied into the XMP, clear the body. |
35 |
while (b.lastChild) { b.removeChild(b.lastChild); } |
36 |
|
37 |
// Insert the XMP and load Strapdown.js to render it. |
38 |
b.appendChild(xmp); |
39 |
b.appendChild(strapdown); |
40 |
}); |