Skip to content

Commit

Permalink
Add support for all mdast-util-toc options
Browse files Browse the repository at this point in the history
Such as `ordered`, `prefix`, and `parents`, plus everything that might
be added in the future.

Related to GH-31.
  • Loading branch information
wooorm committed Feb 5, 2021
1 parent 5f0e35a commit 00c466f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 deletions.
18 changes: 6 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ var util = require('mdast-util-toc')

module.exports = toc

var defaultHeading = 'toc|table[ -]of[ -]contents?'

function toc(options) {
var settings = options || {}
var heading = settings.heading || defaultHeading
var depth = settings.maxDepth || 6
var tight = settings.tight
var skip = settings.skip

return transformer

function transformer(node) {
var result = util(node, {
heading: heading,
maxDepth: depth,
tight: tight,
skip: skip
})
var result = util(
node,
Object.assign({}, settings, {
heading: settings.heading || 'toc|table[ -]of[ -]contents?'
})
)

if (result.index === null || result.index === -1 || !result.map) {
return
Expand Down
24 changes: 4 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,8 @@ Generate a table of contents.
##### `options`

###### `options.heading`

`string?`, default: `'toc|table[ -]of[ -]contents?'` — Heading to look for,
wrapped in `new RegExp('^(' + value + ')$', 'i')`.

###### `options.maxDepth`

`number?`, default: `6` — Maximum heading depth to include in the table of
contents, This is inclusive, thus, when set to `3`, level three headings,
are included (those with three hashes, `###`).

###### `options.tight`

`boolean?`, default: `false` — Whether to compile list-items tightly.

###### `options.skip`

`string?` — Headings to skip, wrapped in `new RegExp('^(' + value + ')$', 'i')`.
Any heading matching this expression will not be present in the table of
contents.
All options are passed to [`mdast-util-toc`][util], with the exception that
`heading` defaults to `'toc|table[ -]of[ -]contents?'`.

## Security

Expand Down Expand Up @@ -225,3 +207,5 @@ abide by its terms.
[rehype]: https://github.com/rehypejs/rehype

[hast]: https://github.com/syntax-tree/hast

[util]: https://github.com/syntax-tree/mdast-util-toc#options

0 comments on commit 00c466f

Please sign in to comment.