Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following markdown document:




--- text ---


--- text---


--- text----



I would like to make a clickable table of contents out of it, similar to the way LaTex does, but can't find a tool that does this, which suggests to me that we should build one.

The tool should collect 'H1' headings and 'H2' headings such that it assigns the number 1 to Heading-a and the number 1.1. to Heading-b, 1.2. to Heading-c, 2. to Heading-d, 2.1. to Heading-e and so on, such that we should get the following Table of contents:

  1. Heading-a
  1.1. Heading-b
  1.2. Heading-c
  2. Heading-d
  2.1. Heading-e

How can I do this with Python/AWK/SED?

share|improve this question
Why don't you just use LaTeX? – jtbandes Jul 25 '09 at 21:25
Thank you for your answers! – Masi Jul 26 '09 at 5:10
@jtbandes: The syntax of Markdown is easier to read, faster to type and easier to compile than that of LaTex. – Masi Jul 26 '09 at 5:11

3 Answers 3

up vote 8 down vote accepted

The Markdown in Python implementation has support for extensions one of which includes Table of Contents generation. Additionally Pandoc (which is a Haskell markup->PDF has support for markdown (in addition to a bunch of other formats) and can output pretty HTML, LaTeX, PDFs, etc.

share|improve this answer
Your answer raised another problem in installing the extensions at the thread… – Masi Jul 26 '09 at 5:10

See this article for a comparison of lightweight markup languages with some information on tables of contents that might lead you in the direction of a solution.

share|improve this answer
The link is not working. – Masi Jul 26 '09 at 4:23
The link works for me. – Dennis Williamson Jul 26 '09 at 8:44
It seems to be the case that the original author has just removed the blog post such that you have the article in your cache. – Masi Jul 26 '09 at 12:47
The article can be found at Google's cache:… – Masi Jul 26 '09 at 12:48

If you already have headings, you can try github-markdown-toc is able to process stdin, local and remote files, for example:

cat ~/projects/Dockerfile.vim/ | ./gh-md-toc -

or creating a local

./gh-md-toc ~/projects/Dockerfile.vim/
share|improve this answer
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – DavidPostill Oct 23 at 9:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.