Skip to content

Commit 407d988

Browse files
committed
Merge pull request #200 from nasa/open-toc
[Documentation] Add table of contents
2 parents 6ee622b + 21739ff commit 407d988

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

docs/gendocs.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
var CONSTANTS = {
3131
DIAGRAM_WIDTH: 800,
3232
DIAGRAM_HEIGHT: 500
33-
};
33+
},
34+
TOC_HEAD = "# Table of Contents";
3435

3536
GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be defined
3637
(function () {
@@ -44,6 +45,7 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
4445
split = require("split"),
4546
stream = require("stream"),
4647
nomnoml = require('nomnoml'),
48+
toc = require("markdown-toc"),
4749
Canvas = require('canvas'),
4850
options = require("minimist")(process.argv.slice(2));
4951

@@ -110,6 +112,9 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
110112
done();
111113
};
112114
transform._flush = function (done) {
115+
// Prepend table of contents
116+
markdown =
117+
[ TOC_HEAD, toc(markdown).content, "", markdown ].join("\n");
113118
this.push("<html><body>\n");
114119
this.push(marked(markdown));
115120
this.push("\n</body></html>\n");
@@ -133,8 +138,8 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
133138
customRenderer.link = function (href, title, text) {
134139
// ...but only if they look like relative paths
135140
return (href || "").indexOf(":") === -1 && href[0] !== "/" ?
136-
renderer.link(href.replace(/\.md/, ".html"), title, text) :
137-
renderer.link.apply(renderer, arguments);
141+
renderer.link(href.replace(/\.md/, ".html"), title, text) :
142+
renderer.link.apply(renderer, arguments);
138143
};
139144
return customRenderer;
140145
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
"split": "^1.0.0",
2323
"mkdirp": "^0.5.1",
2424
"nomnoml": "^0.0.3",
25-
"canvas": "^1.2.7"
25+
"canvas": "^1.2.7",
26+
"markdown-toc": "^0.11.7"
2627
},
2728
"scripts": {
2829
"start": "node app.js",

0 commit comments

Comments
 (0)