-
-
Notifications
You must be signed in to change notification settings - Fork 1
API
4r7d3c0 edited this page Mar 19, 2020
·
7 revisions
The programmatic use of Documentary is intended for developers who want to use this software in their projects.
Toc
is a transform stream which can generate a table of contents for incoming markdown data. For every title that the transform sees, it will push the appropriate level of the table of contents.
When creating a new Toc
instance, it will accept the following configuration object.
Property | Type | Description | Example |
---|---|---|---|
skipLevelOne |
boolean | Start the table of contents from level 2, i.e., excluding the # title. |
For example, the following code:
# Hello World
## Table Of Contents
## Introduction will be compiled to - [Table Of Contents](#table-of-contents)
- [Introduction](#introduction) when - [Hello World](#hello-world)
* [Table Of Contents](#table-of-contents)
* [Introduction](#introduction) when |
Create a new instance of a Toc
stream.
/* yarn example/toc.js */
import { Toc } from 'documentary'
import Catchment from 'catchment'
import { createReadStream } from 'fs'
(async () => {
try {
const md = createReadStream('example/markdown.md')
const rs = new Toc()
md.pipe(rs)
const { promise } = new Catchment({ rs })
const res = await promise
console.log(res)
} catch ({ stack }) {
console.log(stack)
}
})()
- [Table Of Contents](#table-of-contents)
- [CLI](#cli)
* [`-j`, `--jsdoc`: Add JSDoc](#-j---jsdoc-add-jsdoc)
- [API](#api)
- [Copyright](#copyright)