npm install -g markdown-toc
Insert the following snippet into your markdown file:
<!-- toc -->
This is where the table will be!
<!-- tocstop -->
# Header 1
## Subheader
## Subheader 2
# Header 2
## Another subheader
After running
markdown-toc -i documentation.md
your file will look like this:
<!-- toc -->
- [Header 1](#header-1)
* [Subheader](#subheader)
* [Subheader 2](#subheader-2)
- [Header 2](#header-2)
* [Another subheader](#another-subheader)
<!-- tocstop -->
# Header 1
## Subheader
## Subheader 2
# Header 2
## Another subheader
This trick also works with .Rmd
files!
Unfortunately this doesn't work with Jupyter notebooks, but there's an nb-extension for it.