This is a fork that places a <h4>Table of Contents</h4>
within in the <div class="table-of-contents">
.
markdown-it-table-of-contents
A table of contents plugin for Markdown-it. Based on https://github.com/samchrisinger/markdown-it-toc but simpler, a bit more customizable and with a default slugifier that matches that of https://www.npmjs.com/package/markdown-it-anchor.
Usage
var MarkdownIt = ;var md = ;md; // Optional, but makes sense as you really want to link to somethingmd;
Then add [[toc]]
where you want the table of contents to be added in your markdown.
Example markdown
This markdown:
# Heading[[toc]]## Sub heading 1Some nice text## Sub heading 2Some even nicer text
... would render this HTML using the default options specified in "usage" above:
HeadingHeadingSub heading 1Sub heading 2Sub heading 1Some nice textSub heading 2Some even nicer text
Options
You may specify options when use
ing the plugin. like so:
md;
These options are available:
Name | Description | Default |
---|---|---|
"includeLevel" | Headings levels to use (2 for h2:s etc) | [1, 2] |
"containerClass" | The class for the container DIV | "table-of-contents" |
"slugify" | A custom slugification function | string.js' slugify |
"markerPattern" | Regex pattern of the marker to be replaced with TOC | /^\[\[toc\]\]/im |
"listType" | Type of list (ul for unordered, ol for ordered) |
ul |
"format" | A function for formatting headings (see below) | undefined |
format
is an optional function for changing how the headings are displayed in the TOC.
{ // manipulate the headings as you like here. return manipulatedHeadingString;}