Table of Contents in Markdown, using only the standard / out of the box Github Pages tooling?

纵然是瞬间 提交于 2019-12-22 09:21:43

问题


Trying to setup up a blog / documentation using purely hosted / "out of the box" GitHub Pages Jekyll; I am specifically trying to avoid having to run Jekyll locally (although I can).

I have tried http://www.seanbuscay.com/blog/jekyll-toc-markdown/ but that doesn't work.

Is this possible, or does it truly require additional tooling?


回答1:


By default Jekyll uses Kramdown, it already comes with a TOC generator. You don't need a plugin for this so it will work with github-pages.

kramdown supports the automatic generation of the table of contents of all headers that have an ID set. Just assign the reference name “toc” to an ordered or unordered list by using an IAL and the list will be replaced with the actual table of contents, rendered as nested unordered lists if “toc” was applied to an unordered list or else as nested ordered lists. All attributes applied to the original list will also be applied to the generated TOC list and it will get an ID of markdown-toc if no ID was set.

# Contents
{:.no_toc}

* Will be replaced with the ToC, excluding the "Contents" header
{:toc}

# H1 header

## H2 header

That will give you:

  <h1 class="no_toc" id="contents">Contents</h1>

<ul id="markdown-toc">
  <li><a href="#h1-header" id="markdown-toc-h1-header">H1 header</a>    <ul>
      <li><a href="#h2-header" id="markdown-toc-h2-header">H2 header</a></li>
    </ul>
  </li>
</ul>

<h1 id="h1-header">H1 header</h1>

<h2 id="h2-header">H2 header</h2>

https://kramdown.gettalong.org/converter/html.html#toc



来源:https://stackoverflow.com/questions/48071478/table-of-contents-in-markdown-using-only-the-standard-out-of-the-box-github-p

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