Skip to content

Commit

Permalink
Add support for skipping headings
Browse files Browse the repository at this point in the history
Related to syntax-tree/mdast-util-toc#61
Closes GH-24.

Reviewed-by: Christian Murphy <[email protected]>
Reviewed-by: Merlijn Vos <[email protected]>
Reviewed-by: Titus Wormer <[email protected]>
BarryThePenguin authored and wooorm committed Jul 9, 2019
1 parent a08b584 commit 5efe793
Showing 6 changed files with 81 additions and 2 deletions.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -11,14 +11,16 @@ function toc(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
tight: tight,
skip: skip
})

if (result.index === null || result.index === -1 || !result.map) {
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -105,6 +105,12 @@ are included (those with three hashes, `###`).

`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.

## Related

* [`remark-slug`][slug]
3 changes: 3 additions & 0 deletions test/fixtures/skip/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"skip": "example|notes?"
}
27 changes: 27 additions & 0 deletions test/fixtures/skip/input.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Normal

## Table of Contents

## Alpha

## Bravo

### Example

### Note

## Charlie

### Note

## Delta

### Examples

## Echo

### Notes

## Foxtrot

## Example
41 changes: 41 additions & 0 deletions test/fixtures/skip/output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Normal

## Table of Contents

- [Alpha](#alpha)

- [Bravo](#bravo)

- [Charlie](#charlie)

- [Delta](#delta)

- [Examples](#examples)

- [Echo](#echo)

- [Foxtrot](#foxtrot)

## Alpha

## Bravo

### Example

### Note

## Charlie

### Note

## Delta

### Examples

## Echo

### Notes

## Foxtrot

## Example
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

var test = require('tape')
var fs = require('fs')
var path = require('path')
var test = require('tape')
var remark = require('remark')
var negate = require('negate')
var hidden = require('is-hidden')

0 comments on commit 5efe793

Please sign in to comment.