Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a table of contents in markdown-mode?

I am using emacs in markdown-mode to preview a markdown document, but there is no a table of contents in the HTML page previewed after typing C-x C-x p.

cat ~/.emacs

(add-to-list 'load-path "~/.emacs.d")  

(autoload 'markdown-mode "markdown-mode"
   "Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))

(autoload 'gfm-mode "markdown-mode"
   "Major mode for editing GitHub Flavored Markdown files" t)
(add-to-list 'auto-mode-alist '("README\\.md\\'" . gfm-mode))

(custom-set-variables
 '(markdown-command "/usr/bin/pandoc --toc -f markdown_github -t html"))

PS: I can use pandoc command pandoc --toc -f markdown_github to make a HTML page with a table of contents from a markdown document.

How to solve it? Thx in advanced!

like image 631
Big Shield Avatar asked Feb 22 '17 13:02

Big Shield


People also ask

Can you create a table in Markdown?

To add a table, use three or more hyphens ( --- ) to create each column's header, and use pipes ( | ) to separate each column. For compatibility, you should also add a pipe on either end of the row. Cell widths can vary, as shown below.

What is TOC in Markdown?

The table of contents (TOC) is implemented as Markdown list. A TOC is just a type of Markdown lists.


1 Answers

It's super easy with the package markdown-toc, in melpa. Just call it with M-x.

source: http://wikemacs.org/wiki/Markdown#Generate_a_table_of_content

If you have many identical titles, the anchors have to be distinguished, and you'll rely on npm's markdown-toc.

like image 182
Ehvince Avatar answered Oct 10 '22 07:10

Ehvince