-
Notifications
You must be signed in to change notification settings - Fork 129
Insert automatically generated table of contents TOC on rendered markdown files like README.md. #215
Comments
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. |
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 |
👍 |
2 similar comments
+1 |
+1 |
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:
|
@maxlinc thanks a lot for the schacon link! I was really curious to why he used Asciidoc on Pro Git 2. |
@maxlinc - I subscribe the thanksgiving by cirosantilli! 👍 |
@ekalinin I suppose this won't work for private repos? |
@Mike-Charles yes, unfortunately github-markdown-toc won't work for private repos |
+1 |
2 similar comments
+1 |
+1 |
+1 |
+1 |
Why does a solution have to extend markdown? @ekalinin's code can already create a ToC markdown file, so GH could just generate a new ToC on every change to readme.md, and display that file on the project's homepage above the real readme.md. Everyone gets a ToC for free with their readme.md files (and presumably can opt-in/out if they wish) without changing a single line of code. |
@MikeyBurkman - It does not need to, but if it did it, it would become part of the specification, and all libraries that works against that specification would support it (e.g.: github-markdown preview of the readme file in your IDE/editor of choice). Preview of the TOC is important: on large documents is easy to get the levels wrong, for example. |
+1 |
2 similar comments
+1 |
+1 |
@quasipedia Surely you aren't saying that the necessity of a preview tool is a good reason to change the MD spec! That's like saying that not having some MD tool installed on my computer means I can't edit MD. Github already have a MD preview tool... just extend it to also preview the TOC. As for external tools: the script to generate TOC from MD is publicly available. They can integrate if and when they want, and that integration would not be much different than supporting another MD spec. Only now your tools have to adjust, not every single user. |
@MikeyBurkman - Surely you aren't saying that improving on standards is bad! ;) Seriously: I can't but repeat myself: the solution does not need to extentd MD. GitHub has a history of creating standards that are to all effects "forks" of previously existing ones (GFM, TOML...). Since GFM is already a different standard than MD, and since GitHub is its creator and maintainer, it wouldn't surprise me if they would implement the TOC as part if it... ...but if that doesn't happen, I am just fine! :) |
+1 |
+1 Have tried MarkdownTOC for sublime text today. Which might have been a alternative but sadly it doesn't work nearly well enough. No links and seems broken as it doesn't parse my markdown headings correctly. [EDIT] |
FWIW, I made this. https://github.com/ajkochanowicz/Smooth-ToCer Obviously, it won't work with github readme files, but for any other markdown content that needs a TOC and can run JS... |
+1 |
2 similar comments
+1 |
+1 |
@botatoes this is such a great feature!!! I am using GitHub to teach a class and am very happy about the TOC! One request, is it possible to have an option in the repo for it to be "expanded on default" and have it on the right side so it doesn't cover the headers? something like this would be ideal: regardless, thank you for this amazing feature!! |
Minor concerns with the new feature:
|
@captn3m0 It doesn't appear on Android too. And also it works on Chrome Android |
@captn3m0 Our web implementations is the most to date. The mobile app team has their own backlog which means features aren't always aligned to ship at the same time. TOC should work on web mobile view though. Let me know if that's not the case for you. |
Seems this feature was announced here: |
@thorade there will be a changelog and updated docs. I'm just waiting for the additional non-README Markdown support coming either late this week or early next week before I push out the docs. |
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). |
@botatoes Thanks very much! Is there an ETA for TOC support in the GitHub mobile apps? |
[[TOC]] * No, this shouldn't be closed! 😞True, this is a nice feature. Why?Not obvious AT ALL, and does not seem like a part of the Markdown content. Image for reference: But...Why complicate this? I mean, it's cool and all, but why not just go with this, the
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 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.
|
Still not seeing table of contents on Github Wiki pages :( |
@xantari Don't worry, it'll be there soon enough, give it another – say – 8 years. 😉 |
@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 😅 |
@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? |
I just got this working on GitLab via |
@hectoralicea That’s also how Azure DevOps does it as well it’s so easy |
Wiki ToC issue is #504 |
Because the diff of this is a nightmare, I have made no substantial changes. All I did was reorganize the existing sections and add some TODOs for parts to fill in. This means the resulting prose doesn't flow and is weird in some places. I'll fix that in follow up PRs, but I wanted to do the reordering separately since the diff is unreadable. I also removed the TOC from the top since GitHub generates one automatically: isaacs/github#215 (comment)
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:
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:
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
The text was updated successfully, but these errors were encountered: