Generate Table of Contents in your Markdown-files
Yes, there are tons of scripts like this already.
This script is for those of us who want the following:
- Support multiple files out-of-the-box, i.e.
hohhoijaa *.md - For CI use,
--checkto validate existing TOCs but not write anything - No external dependencies, just simple text matching (see
src/*.test.js, it works just fine)
npm install --save-dev hohhoijaaAdd <!-- hohhoijaa --><!-- /hohhoijaa --> to each markdown file where you want the generated Table of Contents to be inserted.
Files without this template tag will be unaffected.
Basic usage:
hohhoijaa README.mdBash wildcards work:
hohhoijaa *.mdValidate existing TOCs (if any file needs updating, will exit with 1; otherwise with 0):
hohhoijaa --check *.mdBy default the first H1-level heading is omitted. Can choose to keep it:
hohhoijaa --keep-h1 *.mdTest files are named src/*.test.js.
yarn testMIT