0.0.2 • Published 9 years ago

magu-plugin-toc v0.0.2

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

magu-plugin-toc

Magu plugin that generate table of contents

Build Status XO code style

Install

yarn add magu-plugin-toc
npm install magu-plugin-toc

Usage

magu({}, [toc({
  // Below is the default value
  listTemplate: '<ul class="toc__list toc--level-{level}"></ul>',
  itemTemplate: '<li class="toc__item toc--level-{level}">{text}</li>',
  selector: '.toc__box'
})])
  .process(`${__dirname}/path/to/file.md`)
  .then(result => console.log(result.html));

Options

Please think that the template part is using sindresorhus/pupa like this.

pupa(template, {text, level});
  • listTemplate (default:'<ul class="toc__list toc--level-{level}"></ul>')
  • itemTemplate (default:'<li class="toc__item toc--level-{level}">{text}</li>')
  • selector (default:.toc__box)

Example

<div class="toc__box"></div>
# headline
## sub
## sub
### subsub
# headline
# headline
### subsub

result like this.

<div class="toc__box"><ul class="toc__list toc--level-1"><li class="toc__item toc--level-1">headline</li><li class="toc__item toc--level

-1"><ul class="toc__list toc--level-2"><li class="toc__item toc--level-2">sub</li></ul></li><li class="toc__item toc--level-1"><ul class
="toc__list toc--level-2"><li class="toc__item toc--level-2">sub</li><li class="toc__item toc--level-2"><ul class="toc__list toc--level-
3"><li class="toc__item toc--level-3">subsub</li></ul></li><li class="toc__item toc--level-2"><ul class="toc__list toc--level-3"><li cla
ss="toc__item toc--level-3">subsub</li></ul></li></ul></li></ul><ul class="toc__list toc--level-1"><li class="toc__item toc--level-1">he
adline</li></ul><ul class="toc__list toc--level-1"><li class="toc__item toc--level-1">headline</li></ul></div>

<h1 id="headline">headline</h1>
<h2 id="sub">sub</h2>
<h2 id="sub">sub</h2>
<h3 id="subsub">subsub</h3>
<h1 id="headline">headline</h1>
<h1 id="headline">headline</h1>
<h3 id="subsub">subsub</h3>

License

The MIT License (MIT) Copyright (c) 2016 nju33 nju33.ki@gmail.com