title: Jekyll Kramdown T.O.C. not building
body: <p>Here's the final output of what I'd like to have:</p>
  
  <pre><code>&lt;article itemscope itemtype="http://schema.org/BlogPosting"&gt;
      &lt;header&gt;
          &lt;h1&gt;Jekyll Table of Contents with Kramdown
          &lt;/h1&gt;
      &lt;/header&gt;
      &lt;nav aria-label="Table of Contents"&gt;
          &lt;ul&gt;
              &lt;li&gt;Topic 1&lt;/li&gt;
              &lt;li&gt;Topic 2&lt;/li&gt;
              &lt;li&gt;Topic 3&lt;/li&gt;
          &lt;/ul&gt;
      &lt;nav&gt;
      &lt;section itemprop="articleBody"&gt;
          &lt;p&gt;the main body of the article&lt;/p&gt;
      &lt;/section&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>With a default Jekyll install Kramdown can create a TOC with</p>
  
  <pre><code>* TOC
  {:toc}
  </code></pre>
  
  <p>However <a href="https://jekyllrb.com/tutorials/orderofinterpretation/#markdown-in-include-file-not-processed" rel="nofollow noreferrer">Markdown is not currently supported in HTML includes or Layout files</a>.
  I tried using [Capture and Markdownify}(<a href="https://github.com/jekyll/jekyll/issues/6166#issuecomment-322771527" rel="nofollow noreferrer">https://github.com/jekyll/jekyll/issues/6166#issuecomment-322771527</a>) to add the above TOC call to the layout file without success</p>
  
  <pre><code>// _layouts/post.html
  
  &lt;article&gt;
      &lt;header&gt;
          &lt;h1&gt;Jekyll Table of Contents with Kramdown
          &lt;/h1&gt;
      &lt;/header&gt;
      {% capture toc %}{% include toc.md %}{% endcapture %}
      {{ toc | markdownify }}
      &lt;section itemprop="articleBody"&gt;
          &lt;p&gt;the main body of the article&lt;/p&gt;
      &lt;/section&gt;
  &lt;/article&gt;
  </code></pre>
  
  <p>Adding a inline markdownify works for plain markdown but not the Kramdown TOC call.</p>
  
  <pre><code>// this works
  {% capture md %}
  ## Heading 2
  *Stuff added in my layout*
  {% endcapture %}
  {{ md | markdownify }}
  
  // This doesn't work
  {% capture md %}
  * TOC
  {:toc}
  {% endcapture %}
  {{ md | markdownify }}
  </code></pre>
  
  <p>The only way I see around this is to include some of the layout markup in the post's markdown file.</p>
  
  <pre><code>// _layouts/post.html
  
  &lt;article&gt;
      &lt;header&gt;
          &lt;h1&gt;Jekyll Table of Contents with Kramdown
          &lt;/h1&gt;
      &lt;/header&gt;
      {{ content }}
  &lt;/article&gt;
  
  // _posts/post.md
  
  ---
  layout: post
  ---
  &lt;nav aria-label="Table of Contents"&gt;
      * TOC
      {:toc}
  &lt;/nav&gt;
  
  &lt;section itemprop="articleBody"&gt;
      ## My Heading
      Standard markdown content here
  &lt;/section&gt;
  </code></pre>
  
  <p>The draw back here is that I've now got page markup in my post that can be easily corrupted and a distraction to content editors.</p>
  
  <p>Does anybody see a way round this?</p>