Created
May 19, 2019 04:06
-
-
Save CyberAstronaut101/3410cb0faf31b508ece2733dc2f99354 to your computer and use it in GitHub Desktop.
Markdown TOC generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Quck Node.js script to create the TOC for a *.md markdown file | |
*/ | |
var Remarkable = require('remarkable') | |
var toc = require('markdown-toc') | |
var fs = require('fs') | |
function render(str, options) { | |
return new Remarkable() | |
.use(toc.plugin(options)) // register plugin | |
.render(str); | |
} | |
if(process.argv.length == 2) { | |
console.log("Please enter the README.md file as first command line argument!") | |
return; | |
} | |
fs.readFile(process.argv[2], 'utf8', function(err, data) { | |
if (err) throw err; | |
console.log("Contents of README file passed: " + data); | |
var resultTOC = render(data) | |
console.log("Table of contents to paste into README.md:\n\n"); | |
console.log(resultTOC.content); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment