Markdown TOC Generator
A simple Node.js tool to generate and insert a Table of Contents (TOC) into a Markdown file.
Features
- Automatically insert TOC into the source file
- Add anchor links for headers
- Generate an indented TOC structure
Installation
npm install
Usage
node index.js <markdown-file>
Example:
node index.js example.md
Testing
npm test
Example Output
Before:
# Title 1
## Subtitle 1.1
### Subtitle 1.1.1
## Subtitle 1.2
# Title 2
After:
<!-- TOC START -->
- [Title 1](#title-1)
- [Subtitle 1.1](#subtitle-11)
- [Subtitle 1.1.1](#subtitle-111)
- [Subtitle 1.2](#subtitle-12)
- [Title 2](#title-2)
<!-- TOC END -->
# Title 1
## Subtitle 1.1
### Subtitle 1.1.1
## Subtitle 1.2
# Title 2