You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
Insert automatically generated table of contents TOC on rendered markdown files like README.md. #215
Edit March 2021: GitHub now added a workaround mentioned at: #215 (comment) That is a good step, but I'll keep this open until they actually add a way to add it inside the rendered output (which can be e.g. searched more easily with Ctrl+F).
When I see a manually generated table of contents, it makes me sad.
When I see a huge README that is impossible to navigate without it, it makes me even sadder.
LaTeX has it. Gollum has it. Pandoc has it. So why not GFM?
There are some tools that automate the generation, but they're just an ugly hack:
require a Make before pushes
add output to version control
modify our dear source code for us
Now the bitter part: what syntax to use?
Whatever is chosen, it should be a standard way to extend Markdown, so that other extensions can be added later on.
One possibility is to use Kramdown extension syntax and insert the TOC with {:toc max_level=3 }.
Redcarpet already has a command that generates the TOC: Redcarpet::Render::HTML_TOC, but no way to insert it, and no standard way to extend markdown.
changed the title [-]Allow to insert a table of contents TOC on rendered markdown files like README.md.[/-][+]Insert automatically generated table of contents TOC on rendered markdown files like README.md.[/+]on Jun 21, 2014
You can automatically generate TOC via http://doctoc.herokuapp.com/. There is also an npm package available here to do it on the command line.
But yes, these are ultimately just manual methods because you need to manually copy and paste the TOC into the markdown. But one benefit of it is that the toc is maintained everwhere, even across apps that don't use GFM for rendering.
Reacted by Hein Pauwelyn, Ashwin Jayaprakash, Charles-A. Francisco, Anurag Kapur, Hraban, José Cage , Oli Beatson, Ambrose Little, Serhii Potapov, David Gilbertson and 2 more
Reacted by B. Ogan Mancarcı, b3n01t, Florian Grignon, Frank, Dmytro Burdyga, Victor Pierre, Jesse Olsen, Jonathan Leroy, Manos, Brian and 61 more
I hope GitHub fix some standard extension syntax, possibly backing up Kramdown's, and potentially settle the existing extension mess with it's influence.
Here's my try to solve this issue without any addional software (on linux) — github-markdown-toc
Reacted by Kirill Zhuharev, Steven Wu, Wilmer Saint-Hilaire, B. Ogan Mancarcı, Nikita Shupeyko, fortran02, Pratyush Nalam, Onur Yılmaz, Charlie Egan, Benjamin Han and 27 more
Reacted by mauricioprado00, tukkek, Ronny Herzog, Ziyang, Gerald Venzl, Wilfried Goesgens, Sam Faulkner, David D'Haese, Man Lam, Sondra Miller and 3 more
Although I'd like to see TOC support in GFM, if you want TOC's rendered by GitHub today than you could switch to asciidoc. Asciidoc has built-in support for TOC, and with the right options it will be rendered by GitHub.
I'm a fan of Markdown so I'm hesitant to asciidoc, but the article on Living the Future of Technical Writing by GitHub's @schacon, which talks about switching from Markdown to Asciidoc, has made willing to consider the jump. There's also several other features other features in asciidoc-samples - besides TOC - that don't seem to have working GFM equivalents. Footnotes, for example.
If you want give asciidoc a shot, you can use pandoc to convert your existing markdown:
Reacted by Ray, Stéphane Lavergne, Walter, Marco Rietveld, Shaun Smiley, Sherman Boyd, Vinícius dos Santos Oliveira, Semyon Pisarev, Horacio Mijail Antón Quiles, Jared Morgan and 25 more
Reacted by Morris Winkler, Chang Chen and Liqiang Liu
Not obvious AT ALL, and does not seem like a part of the Markdown content.
A Table of Contents needs to be a part of the Markdown content, since it refers to the sections in the comment itself.
Image for reference:
There's NO WAY I could ever imagine that clicking that takes me to the ToC of the MD contents.
I first thought it would show a list of files on the same level for file navigation, and I've been using GitX for a long time.
But...
Why complicate this? I mean, it's cool and all, but why not just go with this, the
the simple,
more effective,
flexible (I can choose not to give a ToC),
more obvious (if it's on top and a part of the MD file, it's the ToC of the MD file, duh),
more easy to use by literally all people (that's the global format, intuitive)
(and by all people I mean - even if Robinson Crusoe came back from 30 years on an island and saw this, he'd get it)
way?
Suggestion:
If you want to make the traditional ToC better, I would suggest that we implement something like Wikipedia's ToC with a hide/show option (but better looking). reference
We can choose to give a ToC using a [[_TOC_]] or whatever, and then you can render it. Plus we can keep the cool button if you want. 😄
Or maybe make it a really prominent collapsible sidebar, like we see in docs.
But TLDR is that as of now, that implementation does not warrant closing this issue.
I have a dream! That one day when ToC is implemented better, this will be rendered as a proper ToC
Reacted by Sven Schwyn, albertkun, Anton Petrov, Duarte Cunha Leão, Rémi Bétin, Michalis Kamburelis, Hector Alicea, exquo, ghostlydilemma, Sandy Maguire and 5 more
Reacted by Valentin, Matthis Thorade and Oliver Niebuhr
@CatalanCabbage The reason why we've picked the UI route first instead of injecting Markdown is because GitHub README.md files are rendered elsewhere outside of GitHub UI and injecting Markdown might create unexpected behaviors. That being said, we'll still be considering it for the future as a part of our improve GitHub Flavored Markdown effort.
@xantari I'm driving proposals for Wiki improvements right now and this is definitely on the list but no timeline yet 😅
I just got this working on GitLab via [[_TOC_]] tag. Works great in my editor as well (using Typora). Very surprised GitHub does not support this simple feature.
Reacted by TPS, dvsj, ghostlydilemma, Evgeniy Mamchenko, Leandro Lisboa Penz and rpgoldman
Activity
[-]Allow to insert a table of contents TOC on rendered markdown files like README.md.[/-][+]Insert automatically generated table of contents TOC on rendered markdown files like README.md.[/+]captn3m0 commentedon Jun 22, 2014
You can automatically generate TOC via http://doctoc.herokuapp.com/. There is also an npm package available here to do it on the command line.
But yes, these are ultimately just manual methods because you need to manually copy and paste the TOC into the markdown. But one benefit of it is that the toc is maintained everwhere, even across apps that don't use GFM for rendering.
cirosantilli commentedon Jun 22, 2014
I hope GitHub fix some standard extension syntax, possibly backing up Kramdown's, and potentially settle the existing extension mess with it's influence.
ekalinin commentedon Sep 2, 2014
Here's my try to solve this issue without any addional software (on linux) — github-markdown-toc
quasipedia commentedon Oct 22, 2014
👍
ezequielgarcia commentedon Dec 9, 2014
+1
robbyoconnor commentedon Dec 16, 2014
+1
maxlinc commentedon Dec 16, 2014
Another workaround...
Although I'd like to see TOC support in GFM, if you want TOC's rendered by GitHub today than you could switch to asciidoc. Asciidoc has built-in support for TOC, and with the right options it will be rendered by GitHub.
I'm a fan of Markdown so I'm hesitant to asciidoc, but the article on Living the Future of Technical Writing by GitHub's @schacon, which talks about switching from Markdown to Asciidoc, has made willing to consider the jump. There's also several other features other features in asciidoc-samples - besides TOC - that don't seem to have working GFM equivalents. Footnotes, for example.
If you want give asciidoc a shot, you can use pandoc to convert your existing markdown:
cirosantilli commentedon Dec 16, 2014
@maxlinc thanks a lot for the schacon link! I was really curious to why he used Asciidoc on Pro Git 2.
quasipedia commentedon Dec 17, 2014
@maxlinc - I subscribe the thanksgiving by cirosantilli! 👍
mikecharles commentedon Dec 17, 2014
@ekalinin I suppose this won't work for private repos?
ekalinin commentedon Dec 18, 2014
@Mike-Charles yes, unfortunately github-markdown-toc won't work for private repos
sv3ndk commentedon Dec 28, 2014
+1
mockitoguy commentedon Jan 4, 2015
+1
Manuzor commentedon Jan 8, 2015
+1
428 remaining items
botatoes commentedon Apr 14, 2021
Here's the link to the changelog https://github.blog/changelog/2021-04-13-table-of-contents-support-in-markdown-files/ and docs update will come soon. This is now supported for all Markdown files (in the browser).
TPS commentedon Apr 14, 2021
@botatoes Thanks very much! Is there an ETA for TOC support in the GitHub mobile apps?
CatalanCabbage commentedon Apr 18, 2021
[[TOC]] *
@TPS
No, this shouldn't be closed! 😞
True, this is a nice feature.
But what we need is something like what GitLab supports - no-nonsense, just a Table of Contents on top.
Why?
Not obvious AT ALL, and does not seem like a part of the Markdown content.
A Table of Contents needs to be a part of the Markdown content, since it refers to the sections in the comment itself.
Image for reference:

There's NO WAY I could ever imagine that clicking that takes me to the ToC of the MD contents.
I first thought it would show a list of files on the same level for file navigation, and I've been using GitX for a long time.
But...
Why complicate this? I mean, it's cool and all, but why not just go with this, the
(and by all people I mean - even if Robinson Crusoe came back from 30 years on an island and saw this, he'd get it)
way?
Suggestion:
If you want to make the traditional ToC better, I would suggest that we implement something like Wikipedia's ToC with a hide/show option (but better looking). reference
We can choose to give a ToC using a
[[_TOC_]]or whatever, and then you can render it. Plus we can keep the cool button if you want. 😄Or maybe make it a really prominent collapsible sidebar, like we see in docs.
But TLDR is that as of now, that implementation does not warrant closing this issue.
xantari commentedon Apr 18, 2021
Still not seeing table of contents on Github Wiki pages :(
svoop commentedon Apr 18, 2021
@xantari Don't worry, it'll be there soon enough, give it another – say – 8 years. 😉
botatoes commentedon Apr 19, 2021
@CatalanCabbage The reason why we've picked the UI route first instead of injecting Markdown is because GitHub README.md files are rendered elsewhere outside of GitHub UI and injecting Markdown might create unexpected behaviors. That being said, we'll still be considering it for the future as a part of our improve GitHub Flavored Markdown effort.
@xantari I'm driving proposals for Wiki improvements right now and this is definitely on the list but no timeline yet 😅
CatalanCabbage commentedon Apr 19, 2021
@botatoes if that's the reason, then is it possible to
The problems with it now are that it's
Something like this (either on the left or right), prominent like you see in Docs when it's open?
Example from Jest:

hectoralicea commentedon Apr 29, 2021
I just got this working on GitLab via
[[_TOC_]]tag. Works great in my editor as well (using Typora). Very surprised GitHub does not support this simple feature.xantari commentedon Apr 29, 2021
@hectoralicea That’s also how Azure DevOps does it as well it’s so easy
mxmilkiib commentedon May 16, 2021
Wiki ToC issue is #504
Reorder the sections in the macros proposal.