I’m working on a project and need to know if there’s a way to automatically create a table of contents when using GitHub Flavored Markdown. I have a long document with multiple sections and subsections, and manually creating and updating the TOC every time I make changes is really time consuming. I’ve seen some repositories with nice TOCs that seem to update automatically when headers change. Is this something that GFM supports natively, or do I need to use external tools or scripts? I’m looking for the most efficient approach that works well with GitHub’s markdown renderer.
GitHub doesn’t have built-in TOC generation, but I’ve got a solid workaround using GitHub Actions. Set up a workflow that auto-generates and updates your table of contents whenever you push changes. The action scans your markdown files for headers and creates the TOC with proper anchor links. I’ve used this for six months on documentation repos - works perfectly. The TOC stays synced with your content automatically. Just search ‘TOC generator’ actions in the GitHub marketplace - plenty of reliable options that plug right into your workflow.
I’ve been handling big documentation projects for years and swear by pre-commit hooks with TOC generator scripts. Just set up markdown-toc or doctoc locally - it runs automatically when you commit and scans your headers to insert the table of contents between comment markers. Best part? It happens before pushing to GitHub, so your TOC stays current for everyone viewing the repo. Takes maybe five minutes to set up, then you’re done forever. The generated links work perfectly with GitHub’s anchor system.
yeah, gfm itself dosn’t do aut0-TOC, but u can try the ‘Markdown All in One’ ext. for VS Code. it adds a TOC auto and updates when u change headers. super handy with github markdown!