I would like to automatically make tables of contents for pages in my Github wiki written in Markdown. Unfortunately, Github doesn't seem to support this by default, meaning I either have to use Mediawiki syntax instead or make the tables manually.
There isn't an easy fix here by default, but you can add a Chrome extension which will modify Github so that it can create tables of contents.
The extension to do this can be installed here (credit to the Tomancak lab). Once this is installed, you will get another button when editing pages right next to the "h1" "h2" "h3" which will let you automatically add a new table of contents.
The only issues with this extension are that the button is a bit out of sync aesthetically, and the default tables of contents sometimes break. To fix this you just need to replace two lines of code.
To make the button look the same as other Github buttons, you just need to change its class. So, change line 28 to this:
button.className = 'btn btn-sm function-button';
To make the table of contents function correctly, you just need to put it in block quotes using >
.
So, change line 69 to:
var tocStart = '>**Table of contents**\n\n>';
Hope this self answer helps!