【问题标题】:Table of contents using Jekyll and Kramdown使用 Jekyll 和 Kramdown 的目录
【发布时间】:2016-11-19 22:24:50
【问题描述】:

我正在尝试在我的 Jekyll 网站上的页面(不是帖子)上使用 Kramdown 的自动“目录”生成器。

_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 是按字面意思生成的,我没有得到标题列表。

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

我设置错了什么?

【问题讨论】:

    标签: jekyll kramdown


    【解决方案1】:

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

    在您的情况下,您还需要做两件事才能使其发挥作用:

    1. 允许 kramdown 解析内部 html 块:在 _config.yml 添加:

      kramdown:
        parse_block_html: true
      
    2. _includes/toc.html,需要提供种子列表:

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

    【讨论】:

    • 我已经关注了这个,但是在我的站点中,我仍然在我的站点帖子中获得了原始的 html 元素。还有什么我不知道的原因吗?
    • 我正在使用 Jekyll 并投票赞成,因为您需要在上一行或下一行使用无序列表来渲染目录。
    • 似乎 kramdown 只为降价标题生成目录。例如&lt;h2&gt;toptic&lt;/h2&gt; 将不包括在内。
    • 它在布局中不起作用。我们必须将代码放在每个帖子中。
    【解决方案2】:

    我想做something similar,但试图避免在我的帖子页面中有任何类型的标记,类似于你的{% include toc.html %}

    我发现了这个很棒的 Ruby Gem - jekyll-toc,它允许您在布局文件中的任何位置放置 TOC。你在前面启用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      • 1970-01-01
      相关资源
      最近更新 更多