0.0.21 • Published 5 years ago

@okmarvin/markdown-it-toc v0.0.21

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Why another markdown-it table of contents plugin?

Most of the table of contents plugins for markdown-it out there wrap toc in <p></p>, i.e. they are inlined. When you have ul tag inside p, browsers would render it as:

<p></p>
<ol></ol>
<p></p>

It's ugly.

In @okmarvin/markdown-it-toc, it will be wrapped in a nav:

<nav class="toc">
<h2 class="toc__heading">Table of contents</h2>
<ol></ol>
</nav>

Usage

var md = require('markdown-it')({
  html: true,
  linkify: true,
  typography: true
}).use(require('@okmarvin/markdown-it-toc'))
md.render('{:toc}\n# heading one')

Remember to add placeholder {:toc} to where you want table of contents be inserted in your markdown file.

Options

You can specify options too:

NameDescriptionDefault
classcss class for table of contents' containertoc
hMinminimum heading level toc will show1
hMaxmaximun heading level toc will show6
enableHeadingIconadd an icon to heading anchorfalse
headingAnchorClassclass for heading anchoranchor
headingAnchorPrefixprefix for heading anchor
titleHeadingTable of contents