Automatic TOC in github-flavoured-markdown

后端 未结 17 1758
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 09:24

Is it possible to generate an automatic Table of Contents using Github Flavoured Markdown?

17条回答
  •  孤街浪徒
    2020-12-12 09:55

    GitHub Pages (which is basically a wrapper for Jekyll) appears to use kramdown, which implements all of Maruku, and therefore has support for an automatically generated table of contents via atoc attribute:

    * auto-gen TOC:
    {:toc}
    

    The first line just starts an unordered list and is actually thrown away.

    This results in a nested set of unordered lists, using the headers in the document.

    Note: this should work for GitHub Pages, not GitHub Flavored Markdown (GFM) as used in comments or wiki pages. AFAIK a solution doesn't exist for that.

提交回复
热议问题