If you look here: http://en.wikipedia.org/wiki/Stack_Overflow
You\'ll notice there\'s a little \"Content\" section, if you click on one of the links, it will send you to
Currently it's not possible to do that using markdown syntax (.md
). There is ongoing unofficial discussion about automatically generating table of contents TOC on rendered markdown files like README.md
which lists some of the ideas.
However there are some other workarounds such as:
Use AsciiDoc
instead as per suggestion from this comment. For example:
:toc: macro
:toc-title:
:toclevels: 99
# Title
toc::[]
## A
### A2
## B
### B2
Check the example at littlebits/react-popover (README.adoc).
Online Table Of Content Generator (raychenon/play-table-of-contents)
It is nicely demonstrated in the Table of Contents of the Markdown Cheatsheet.
##### Table of Contents
[Headers](#headers)
[Emphasis](#emphasis)
...snip...
<a name="headers"/>
## Headers
If you hover over a Header in a GitHub Markdown file, you'll see a little link simple to the left of it, you can also use that link. The format for that link is <project URL#<header name>
. The <header name>
must be all lower case.
If you are not in the position to stick with Markdown, you can do as below:
- on GitHub/wiki: switch Markdown to MediaWiki. Use
__TOC__
Syntax. See sample.- on GitHub/repo: switch Markdown to AsciiDoc. Use
:toc:
Syntax. See demo.
However, using Markdown files in GitHub/repo, you can get it on GitHub Pages like in Wikipedia
- when Jekyll is activated, it generates GitHub Pages using Kramdown by default
- Kramdown comes with
Table Of Content
. Use{:toc}
Syntax. See the explanation.
You can choose the Edit mode "MediaWiki" which will generate a toc for the headers, e.g.
== First ==
== Second ==
Since github cannot use TOC
directly, but we have other alternatives.
You can automatically generate TOC via Online tool:
Generate TOC Table of Contents from GitHub Markdown or Wiki Online
or via Local tool:
github-markdown-toc
One possible (semi-automated) solution is Eugene Kalinin's github-markdown-toc
. This tool essentially crunches through your README.md
file and snarfs out #
's headings to create a TOC.
Feed your README.md
to the script (as noted in Eugene's README.md
)
cat README.md | bash github-markdown-toc
Cut and paste generated TOC and place it at the top of your README.md
file
Note that this bash
implementation only works on Linux (from what I can tell).
As a side note, there is a golang implementation and is probably more of a hassle to get working.