Adding Tables of Contents to Markdown

Once any document gets over a certain length, a table of contents can be useful. I have a favourite markdown table-of-contents tool but it usually takes me a trip to the search engine to remember what it is! (tl;dr: github-markdown-toc )

This tool generates a neat, nested table of contents based on the titles in the file you give it, and outputs it to standard out. My command looks something like:

gh-md-toc /path/to/project/README.md

Capture the output, put it at the top of your file, and you are all set! For example, a Go SDK project I was working on recently. It’s such a small thing but it improves user experience and only takes a moment. When it’s time to update, just delete what you have and regenerate a new one!

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)