Content using Jekyll and Kramdown

I am trying to use the Kramdown auto "Content" generator on a page (rather than a post) on my Jekyll site.

_includes / toc.html

<nav> <h4>Table of Contents</h4> {:toc} </nav> 

my_cool_stuff / my_cool_page.md

 --- layout: page --- {% include toc.html %} # The title of my page ## The Subtitle of my page 

HTML is being generated literally and I am not getting a list of headers.

 <nav> <h4 class="toc_title">On This Page</h4> {:toc} </nav> 

What am I installing incorrectly?

+6
source share
2 answers

{: toc} kramdown tag to automatically generate a content table .

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

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

     kramdown: parse_block_html: true 
  • in _includes/toc.html , you need to provide a list of seeds:

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

I wanted to do something similar , but tried to avoid the markup on my posts page, similar to your {% include toc.html %} .

I found this great Ruby Gem - jekyll-toc , which allows you to place TOC anywhere in the layout file. You include it in the front subject.

0
source

All Articles