Table of contents using Jekyll and Kramdown

心已入冬 提交于 2019-12-03 12:16:12

{:toc} is kramdown tag for automatic Table of content generation.

In your case, you need two more things to make it work :

  1. Allow kramdown to parse inside html blocks : in _config.yml add :

    kramdown:
      parse_block_html: true
    
  2. in _includes/toc.html, you need to provide a seed list :

    <nav>
      <h4>Table of Contents</h4>
      * this unordered seed list will be replaced by toc as unordered list
      {:toc}
    </nav>
    

I wanted to do something similar but was trying to avoid having any kind of markup in my post page, similar to your {% include toc.html %}.

I found this great Ruby Gem - jekyll-toc that allows you to place a TOC anywhere in a layout file. You enable it in the front matter.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!