Added Table of Contents generation

This commit is contained in:
Andrew Henry
2015-10-15 12:35:38 -07:00
parent d3ff0a258e
commit efb7611f6e
7 changed files with 293 additions and 49 deletions

View File

@ -117,6 +117,22 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
};
return transform;
}
function strip() {
var patternsToStrip = [
"^<!--"
]
var transform = new stream.Transform({ objectMode: true });
transform._transform = function (chunk, encoding, done) {
//If chunk does not match pattern, keep it, else discard (by not
// pushing into stream)
if (!chunk.trim().match(patternsToStrip.join("|"))){
this.push(chunk);
}
done();
}
return transform;
}
// Custom renderer for marked; converts relative links from md to html,
// and makes headings linkable.
@ -167,6 +183,7 @@ GLOBAL.window = GLOBAL.window || GLOBAL; // nomnoml expects window to be define
fs.createReadStream(file, { encoding: 'utf8' })
.pipe(split())
.pipe(nomnomlifier(destPath, prefix))
.pipe(strip())
.pipe(gfmifier())
.pipe(fs.createWriteStream(destination, {
encoding: 'utf8'