How can I make a table of contents for a markdown document with Python/AWK/SED?
Solution 1
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.
Solution 2
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/README.md | ./gh-md-toc -
or creating a local README.md
:
./gh-md-toc ~/projects/Dockerfile.vim/README.md
Related videos on Youtube
Comments
-
indi almost 2 years
I have the following markdown document:
Heading-a ========== ---text--- Heading-b ------------ --- text --- Heading-c ---------- --- text--- Heading-d ======= --- text---- Heading-e --- ...
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. toHeading-b
, 1.2. toHeading-c
, 2. toHeading-d
, 2.1. toHeading-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?
-
Assembler almost 15 yearsWhy don't you just use LaTeX?
-
indi almost 15 years@jtbandes: The syntax of Markdown is easier to read, faster to type and easier to compile than that of LaTex.
-
-
indi almost 15 yearsThe link is not working.
-
indi almost 15 yearsYour answer raised another problem in installing the extensions at the thread superuser.com/questions/13075/…
-
indi almost 15 yearsIt seems to be the case that the original author has just removed the blog post such that you have the article in your cache.
-
indi almost 15 yearsThe article can be found at Google's cache: site:alexandrenotebook.blogspot.com/2008/01/…