8

How to generate table of contents with links for GitHub markdown with pandoc?

I tried pandoc -f markdown_github --toc -s -S README.md -o new.md It does create a table of contents but it has no link to sections.

I'm trying to generate a table of contents such as:

enter image description here

on a Windows machine.

Franck Dernoncourt
  • 20,384
  • 48
  • 186
  • 322

1 Answers1

10

Try the following command:

pandoc -f gfm --toc -s README.md -o r.md

as it worked fine for me with the latest version of pandoc.

With pandoc's own README.md, I got this ToC:

-   [Pandoc](#pandoc)
    -   [The universal markup
        converter](#the-universal-markup-converter)
    -   [Installing](#installing)
    -   [Documentation](#documentation)
    -   [Contributing](#contributing)
    -   [License](#license)
kenorb
  • 24,736
  • 27
  • 129
  • 199
John MacFarlane
  • 151
  • 1
  • 3
  • Thanks. Equivalent with a pipeline: `cat README.md | pandoc --from markdown --toc -s --to markdown -` (though it generates the entire file with contents). – Sridhar Sarnobat Oct 02 '21 at 00:26
  • Note: When I use `--toc` and open the file, I get a security prompt ("This document contains fields that may refer to other files.") – Niek Nov 03 '22 at 11:30