Produce a Table of Contents from a Markdown (.md) document.
This simple shell script reads a file that is in markdown format and extracts all the headers. From this it produces a small snippet of markdown which constitutes a table of contents of links.
This is a shell script. Uses sed
and awk
and of course /bin/sh
.
Oh and it uses grep
. No other dependencies.
tocgen.sh
- this is the shell script to runSAMPLE.md
- this is a sample fileSAMPLE_TOC.md
- this is the output of the script.
Standard Usage:
$ ./tocgen.sh README.md > toc.md
Split Usage:
$ ./tocgen.sh pass1 README.md > tmp.txt
Review the file tmp.txt for errors:
$ ./tocgen.sh pass2 tmp.txt > toc.md
This is just made up stuff. The table of contents for the README.md file was produced using this script.
Stuff A goes here.
Stuff B goes here. Now we have more sub stuff:
Here is the first subdivision of Stuff B
Here is the second subdivision of Stuff B
Here is the third subdivision of Stuff B
Stuff C goes here.
In 2023 I was writting a large README.md file. I wanted to have a nice table of contents for it. I searched github for a solution. The solutions all were convoluted pieces of crap. Over designed junk. They didn't work! Standard crappy software by standard crappy developers.
Ken Stauffer