mirror of
https://github.com/ethauvin/kobalt-doc.git
synced 2025-04-25 20:07:11 -07:00
Refactoring toc.
This commit is contained in:
parent
6392d6965c
commit
0a49785494
4 changed files with 30 additions and 48 deletions
40
js/kobalt.js
40
js/kobalt.js
|
@ -56,45 +56,26 @@ function generateNavBar(index) {
|
|||
// Table of contents
|
||||
//
|
||||
|
||||
function countersToHeading(counters) {
|
||||
var result = "";
|
||||
for (var i = 0; i < counters.length; i++) {
|
||||
if (i > 0) result = result + ".";
|
||||
result = result + counters[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function indentSection(count) {
|
||||
var result = "";
|
||||
for (var i = 0; i < count; i++) {
|
||||
result += " ";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function rewriteSection(section, counters) {
|
||||
var result = "";
|
||||
result = result + countersToHeading(counters) + " - " + section.innerHTML;
|
||||
return result;
|
||||
}
|
||||
|
||||
function generateToc() {
|
||||
var sections = document.getElementsByClassName("section");
|
||||
|
||||
var toc = '';//<ul class="nav">\n';
|
||||
var counters = new Array();
|
||||
var currentLevel = 0;
|
||||
var currentLevel = -1;
|
||||
for (i = 0; i < sections.length; i++) {
|
||||
var section = sections[i];
|
||||
var nameNode = section.attributes["name"];
|
||||
var name = nameNode ? nameNode.nodeValue : i;
|
||||
var indentNode = section.attributes["indent"];
|
||||
var indent = indentNode ? indentNode.nodeValue : ".";
|
||||
var ind = 0;
|
||||
var indentAttribute = section.attributes["indent"];
|
||||
if (indentAttribute) {
|
||||
ind = indentAttribute.textContent;
|
||||
}
|
||||
if (! ind) ind = 0;
|
||||
console.log("ind: " + ind + " level:" + currentLevel);
|
||||
var currentCounter = 0;
|
||||
var ind = indent.length;
|
||||
if (ind > currentLevel) {
|
||||
if (ind == 1) {
|
||||
if (ind == 0) {
|
||||
toc += '<ul class="nav">\n';
|
||||
} else {
|
||||
toc += '<ul>\n';
|
||||
|
@ -106,7 +87,8 @@ function generateToc() {
|
|||
currentLevel = ind;
|
||||
}
|
||||
toc += "</ul>\n";
|
||||
|
||||
|
||||
console.log(toc);
|
||||
var tocId = "table-of-contents";
|
||||
var tocTag = document.getElementById(tocId);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue