update toc and toc generator script

This commit is contained in:
Ryan Wu 2015-04-03 19:55:03 +08:00
parent cb0a3af5c5
commit 5698c017c6
2 changed files with 8 additions and 7 deletions

7
toc.js
View file

@ -7,11 +7,12 @@
result;
for (var i = 3; i < headers.length; i++) { //skip H1, history, and toc
var header = headers[i],
headerText = header.textContent.trim(),
headerText = headerText.replace(" ", "-");
headerText = header.textContent.trim();
var anchorText = headerText.toLowerCase(),
anchorText = anchorText.replace(" ", "-");
var hIndex = parseInt(header.nodeName.substring(1)) - 1,
indent = " ".repeat(hIndex),
link = ['<pre>', indent, '* [', headerText, '](', '#', headerText, ')', '\n', '</pre>'];
link = ['<pre>', indent, '* [', headerText, '](', '#', anchorText, ')', '\n', '</pre>'];
result += link.join('');
}
var win = window.open("", "win");