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,
--check
to 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 hohhoijaa
Add <!-- 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.md
Bash wildcards work:
hohhoijaa *.md
Validate existing TOCs (if any file needs updating, will exit with 1; otherwise with 0):
hohhoijaa --check *.md
By default the first H1-level heading is omitted. Can choose to keep it:
hohhoijaa --keep-h1 *.md
Test files are named src/*.test.js
.
yarn test
MIT