Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.
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

Closed

Description

@cirosantilli

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.

Same for GitLab: http://feedback.gitlab.com/forums/176466-general/suggestions/5790538-extension-for-inserting-a-table-of-contents-toc

StackOverflow: 66 upvotes as of 2014-06: http://stackoverflow.com/questions/9721944/automatic-toc-in-github-flavoured-markdown

There is an issue for the library GitHub uses to render markdown at: github/markup#904

Steven! Ragnarök replied with the neutral:

Thanks for the suggestion and links. I'll add it to our internal feature request list for the team to see.

Asciidoc

I got tired of waiting and started using Asciidoc. I recommend it, the format is really good. Just look at the typographical beauty of this: https://github.com/cirosantilli/linux-kernel-module-cheat/blob/7d9102373d60bd159920abfe96d636420afedd67/README.adoc

Activity

  1. 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
  2. captn3m0 commented on Jun 22, 2014

    @captn3m0

    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.

  3. cirosantilli commented on Jun 22, 2014

    @cirosantilli
    CollaboratorAuthor

    I hope GitHub fix some standard extension syntax, possibly backing up Kramdown's, and potentially settle the existing extension mess with it's influence.

  4. ekalinin commented on Sep 2, 2014

    @ekalinin

    Here's my try to solve this issue without any addional software (on linux) — github-markdown-toc

  5. quasipedia commented on Oct 22, 2014

    @quasipedia

    👍

  6. ezequielgarcia commented on Dec 9, 2014

    @ezequielgarcia

    +1

  7. robbyoconnor commented on Dec 16, 2014

    @robbyoconnor

    +1

  8. maxlinc commented on Dec 16, 2014

    @maxlinc

    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:

    pandoc -t asciidoc -f markdown README.md > README.asciidoc
    
  9. cirosantilli commented on Dec 16, 2014

    @cirosantilli
    CollaboratorAuthor

    @maxlinc thanks a lot for the schacon link! I was really curious to why he used Asciidoc on Pro Git 2.

  10. quasipedia commented on Dec 17, 2014

    @quasipedia

    @maxlinc - I subscribe the thanksgiving by cirosantilli! 👍

  11. mikecharles commented on Dec 17, 2014

    @mikecharles

    @ekalinin I suppose this won't work for private repos?

  12. ekalinin commented on Dec 18, 2014

    @ekalinin

    @ekalinin I suppose this won't work for private repos?

    @Mike-Charles yes, unfortunately github-markdown-toc won't work for private repos

  13. sv3ndk commented on Dec 28, 2014

    @sv3ndk

    +1

  14. mockitoguy commented on Jan 4, 2015

    @mockitoguy

    +1

  15. Manuzor commented on Jan 8, 2015

    @Manuzor

    +1

  16. 428 remaining items

  17. botatoes commented on Apr 14, 2021

    @botatoes

    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).

  18. TPS commented on Apr 14, 2021

    @TPS
    Collaborator

    @botatoes Thanks very much! Is there an ETA for TOC support in the GitHub mobile apps?

  19. unpinned this issue on Apr 14, 2021
  20. CatalanCabbage commented on Apr 18, 2021

    @CatalanCabbage

    [[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

    • 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
  21. xantari commented on Apr 18, 2021

    @xantari

    Still not seeing table of contents on Github Wiki pages :(

  22. svoop commented on Apr 18, 2021

    @svoop

    @xantari Don't worry, it'll be there soon enough, give it another – say – 8 years. 😉

  23. botatoes commented on Apr 19, 2021

    @botatoes

    @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 😅

  24. CatalanCabbage commented on Apr 19, 2021

    @CatalanCabbage

    @botatoes if that's the reason, then is it possible to

    • Make it really noticeable so that it's intuitive for non-devs
    • Allow authors to enable or disable it somehow

    The problems with it now are that it's

    • Hard to find
    • Hides content when it's open, so you cannot read the file while keeping this open

    Something like this (either on the left or right), prominent like you see in Docs when it's open?

    Example from Jest:
    image

  25. hectoralicea commented on Apr 29, 2021

    @hectoralicea

    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.

  26. xantari commented on Apr 29, 2021

    @xantari

    @hectoralicea That’s also how Azure DevOps does it as well it’s so easy

  27. mxmilkiib commented on May 16, 2021

    @mxmilkiib

    Wiki ToC issue is #504

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions