Add a linked Table of Contents to any GitHub flavoured Markdown file!
This script specifically adds in explicit links so you can click around the file on GitHub's web interface! (Though this should work on any web interface due to the links!)
Suppose you have a Markdown file with nice headers. But they're all unlinked, and the file is thousands of words long. You don't want your readers to have to scroll through or desperately try to Ctrl-F.
So why not create a linked Table of Contents that lets you get an overview and click the links to jump to the relevant sections!
It even includes go to top functionalities!
This README was even processed with this script! WOW!
Check out this nifty dynamically generated Table of Contents Below!
- Check Out The Example!
1.1 Pre-Processed
1.2 Post-Processed - Usage
2.1 Input Markdown Files
2.2 Running the Script
-
This script only processes level 2 and level 3 headers for neatness' sake
-
Just format your Markdown Files as needed, ensuring all your headers are formatted nicely.
-
Add a single line of "## Table Of Contents" where your want your Table of Contents to begin!
-
The script will then process any headers that come AFTER that Table of Contents Line
## This header will not be processed . . . vvv Table of contents will be inserted here! ## Table Of Contents ^^^ Table of contents will be inserted here! ## This header will get processed
-
-
All Level 3 headers will have a go to top link under them
You need Python to run the script. Run this specifically on Python 3, otherwise it doesn't behave as expected!
$ python linked_toc_adder.py <INPUT NAME> <OPTIONAL:OUTPUT NAME>If no output file is specified, the file that is output will be prepended with
toc_You might also need to put the code where the input file is.
. .
. |\-^-/| .
/| } O.=.O { |\
PS: Did you know that Markdown and methylDragon have the same initials?