Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leisn/markdown-it-toc
Markdown-it plugin to make table of contents, default parse tag [toc],
https://github.com/leisn/markdown-it-toc
markdown markdown-it markdown-it-plugin markdown-it-toc
Last synced: about 1 month ago
JSON representation
Markdown-it plugin to make table of contents, default parse tag [toc],
- Host: GitHub
- URL: https://github.com/leisn/markdown-it-toc
- Owner: leisn
- License: mit
- Created: 2020-06-14T09:36:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-12T23:06:51.000Z (almost 3 years ago)
- Last Synced: 2024-11-18T22:13:19.182Z (about 2 months ago)
- Topics: markdown, markdown-it, markdown-it-plugin, markdown-it-toc
- Language: TypeScript
- Size: 71.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @leisn/markdown-it-toc
![GitHub](https://img.shields.io/github/license/leisn/markdown-it-toc) ![npm (scoped)](https://img.shields.io/npm/v/@leisn/markdown-it-toc)
Markdown-it plugin to make table of contents, default parse tag [toc].
## Installaton
```bash
$ npm install @leisn/markdown-it-toc
or
$ yarn add @leisn/markdown-it-toc
```## E.g. default
### Source markdown
```markdown
[toc]
# H1-1
## H2-1
### H3-1
# H1-2
```### Result document
```html
1
H1-1
#
1.1
H2-1
#
1.1.1
H3-1
#
2
H1-2
#
```## Usage
```javascript
const md = require('markdown-it')(mkOpts) .use(require('@leisn/markdown-it-toc'),options);
console.log(md.render('[toc]\n# h1\n## h2-1\n## h2-2'));
```## Options
* **tocRegexp?: RegExp** Regular expression to detect TOC (default `/\[toc\]/im`).
* **tocTag?: string** Tag for toc root element ( `div` by default ).
* **tocAttrs?: string** Attributes for toc root element( `id="toc" class="toc-wrapper"` by default ).
* **headingAttrs?: string** Attributes for headings `h1,h2,h3...` ( `class="toc-heading"` by default )
```html
--------------------------
# h1 title
--------------------------
h1 title
```* **headingContentAttrs?: string** Attributes for headings content `span` ( `class="toc-heading-content"` by default )
```html
--------------------------
# headingContent
--------------------------
headingContent
```* **getToc?(toc: string): boolean** Get toc result, return false if you don't want it show in the result html document, else return true(default `null`). `toc` : the result html document
* **getPathId?(info): string** Get id content for forwarding in page, (e.g. for `info.paths=[1,2]` default return `toc-no.1-2` )
* **getTocItemContent?(info): string** Content inside toc item `a` (html, include item heading text)
* **getHeadingPrefix?(info): string** Content inside heading (html, before heading text)
```html
--------------------------
# h1 title
--------------------------
{getHeadingPrefix}
h1 title
```* **getHeadingSuffix?(info): string** Content inside heading (html, after heading text)
```html
--------------------------
# h1 title
--------------------------
h1 title
{getHeadingSuffix}
```## Test
```bash
$ npm run test
or
$ yarn test
```## LICENSE
MIT