Skip to content

Commit 94ab096

Browse files
committed
Refactor prose
1 parent 9eef6d1 commit 94ab096

File tree

1 file changed

+75
-54
lines changed

1 file changed

+75
-54
lines changed

readme.md

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,18 @@
33
[![Build][build-badge]][build]
44
[![Coverage][coverage-badge]][coverage]
55
[![Downloads][downloads-badge]][downloads]
6-
[![Chat][chat-badge]][chat]
6+
[![Size][size-badge]][size]
77
[![Sponsors][sponsors-badge]][collective]
88
[![Backers][backers-badge]][collective]
9+
[![Chat][chat-badge]][chat]
910

10-
Generate a Table of Contents from **[mdast][]** trees.
11+
[**mdast**][mdast] utility to generate table of contents.
1112

12-
## Installation
13+
## Install
1314

1415
[npm][]:
1516

16-
```bash
17+
```sh
1718
npm install mdast-util-toc
1819
```
1920

@@ -63,131 +64,151 @@ Yields:
6364

6465
## API
6566

66-
### `toc(node[, options])`
67+
### `toc(tree[, options])`
6768

68-
Generate a Table of Contents from a Markdown document.
69+
Generate a Table of Contents from a [tree][].
6970

70-
Looks for the first heading matching `options.heading` (case insensitive,
71+
Looks for the first [heading][] matching `options.heading` (case insensitive,
7172
supports alt/title attributes for links and images too), and returns a table
72-
of contents for all following headings.
73+
of contents ([list][]) for all following headings.
7374
If no `heading` is specified, creates a table of contents for all headings in
74-
`node`.
75+
`tree`.
76+
`tree` is not changed.
7577

7678
Links to headings are based on GitHub’s style.
77-
Only top-level headings (those not in blockquotes or lists), are used.
78-
(Change this default behavior by using option `parents` as described below)
79-
The given node is not modified.
79+
Only top-level headings (those not in [blockquote][]s or [list][]s), are used.
80+
This default behavior can be changed by passing [`parents`][parents].
8081

8182
##### `options`
8283

8384
###### `options.heading`
8485

85-
Heading to look for (`string`), wrapped in `new RegExp('^(' + value + ')$', 'i')`.
86+
[Heading][] to look for (`string`), wrapped in `new RegExp('^(' + value + ')$',
87+
'i')`.
8688

8789
###### `options.maxDepth`
8890

8991
Maximum heading depth to include in the table of contents (`number`, default:
9092
`6`),
91-
This is inclusive, thus, when set to `3`, level three headings, are included
92-
(those with three hashes, `###`).
93+
This is inclusive: when set to `3`, level three headings are included (those
94+
with three hashes, `###`).
9395

9496
###### `options.tight`
9597

9698
Whether to compile list-items tightly (`boolean?`, default: `false`).
9799

98100
###### `options.prefix`
99101

100-
Add a prefix to links to headings (`string?`, default: `null`).
101-
Useful for example when later going from mdast to hast and sanitizing with
102-
[`hast-util-sanitize`][hast-util-sanitize].
102+
Add a prefix to links to headings in the table of contents (`string?`,
103+
default: `null`).
104+
Useful for example when later going from [mdast][] to [hast][] and sanitizing
105+
with [`hast-util-sanitize`][hast-util-sanitize].
103106

104107
###### `options.parents`
105108

106-
Allows headings to be children of certain node types.
107-
Internally, it uses
108-
[unist-util-is](https://github.com/syntax-tree/unist-util-is) to check.
109-
Hence all types that can be passed in as first parameter can be used here,
110-
including `Function`, `string`, `Object` and `Array.<Test>`.
111-
Check
112-
[documentation](https://github.com/syntax-tree/unist-util-is#readme)
113-
for details.
114-
(default: the first parameter `node`, which only allows top-level headings)
109+
Allows headings to be children of certain node [type][]s (default: the to `toc`
110+
given `tree`, to only allow top-level headings).
111+
Internally, uses [unist-util-is][is] to check, so `parents` can be any
112+
[`is`-compatible][is] test.
115113

116-
Example:
114+
For example, this would allow headings under either `root` or `blockquote` to be
115+
used:
117116

118-
```json
119-
{
120-
"parents": ["root", "blockquote"]
121-
}
117+
```js
118+
toc(tree, {parents: ['root', 'blockquote']})
122119
```
123120

124-
This would allow headings under either `root` or `blockquote` to be used.
125-
126121
##### Returns
127122

128123
An object representing the table of contents.
129124

130125
###### Properties
131126

132127
* `index` (`number?`)
133-
Position of the `heading` in `node`. `-1` if no heading
134-
was found, `null` if no heading was given
128+
[Index][] of the found table of contents [heading][] in `tree`.
129+
`-1` if no heading was found, `null` if no `heading` was given
135130
* `endIndex` (`number?`)
136-
Position of the last node after `heading` before the TOC starts.
137-
`-1` if no heading was found, `null` if no heading was given,
131+
[Index][] of the last node after `heading` before the TOC starts.
132+
`-1` if no heading was found, `null` if no `heading` was given,
138133
same as `index` if there are no nodes between `heading` and the
139134
first heading in the TOC
140135
* `map` (`Node?`)
141-
— List node representing the generated table of contents.
136+
[List][] representing the generated table of contents.
142137
`null` if no table of contents could be created, either because
143-
`heading` didn’t exist, or because no following headings were found
138+
no heading was found or because no following headings were found
144139

145140
## Contribute
146141

147-
See [`contributing.md` in `syntax-tree/mdast`][contributing] for ways to get
142+
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get
148143
started.
144+
See [`support.md`][support] for ways to get help.
149145

150-
This organisation has a [Code of Conduct][coc]. By interacting with this
151-
repository, organisation, or community you agree to abide by its terms.
146+
This project has a [Code of Conduct][coc].
147+
By interacting with this repository, organisation, or community you agree to
148+
abide by its terms.
152149

153150
## License
154151

155152
[MIT][license] © [Jonathan Haines][author]
156153

157154
<!-- Definitions -->
158155

159-
[build-badge]: https://img.shields.io/travis/syntax-tree/mdast-util-toc.svg
156+
[build-badge]: https://img.shields.io/travis/syntax-tree/nlcst-is-literal.svg
160157

161-
[build]: https://travis-ci.org/syntax-tree/mdast-util-toc
158+
[build]: https://travis-ci.org/syntax-tree/nlcst-is-literal
162159

163-
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-util-toc.svg
160+
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/nlcst-is-literal.svg
164161

165-
[coverage]: https://codecov.io/github/syntax-tree/mdast-util-toc
162+
[coverage]: https://codecov.io/github/syntax-tree/nlcst-is-literal
166163

167-
[downloads-badge]: https://img.shields.io/npm/dm/mdast-util-toc.svg
164+
[downloads-badge]: https://img.shields.io/npm/dm/nlcst-is-literal.svg
168165

169-
[downloads]: https://www.npmjs.com/package/mdast-util-toc
166+
[downloads]: https://www.npmjs.com/package/nlcst-is-literal
170167

171-
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
168+
[size-badge]: https://img.shields.io/bundlephobia/minzip/nlcst-is-literal.svg
172169

173-
[chat]: https://spectrum.chat/unified/remark
170+
[size]: https://bundlephobia.com/result?p=nlcst-is-literal
174171

175172
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
176173

177174
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
178175

179176
[collective]: https://opencollective.com/unified
180177

178+
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
179+
180+
[chat]: https://spectrum.chat/unified/syntax-tree
181+
181182
[npm]: https://docs.npmjs.com/cli/install
182183

183184
[license]: license
184185

185186
[author]: https://barrythepenguin.github.io
186187

187-
[mdast]: https://github.com/syntax-tree/mdast
188+
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md
188189

189-
[contributing]: https://github.com/syntax-tree/mdast/blob/master/contributing.md
190+
[support]: https://github.com/syntax-tree/.github/blob/master/support.md
190191

191-
[coc]: https://github.com/syntax-tree/mdast/blob/master/code-of-conduct.md
192+
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
193+
194+
[mdast]: https://github.com/syntax-tree/mdast
195+
196+
[hast]: https://github.com/syntax-tree/hast
192197

193198
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
199+
200+
[is]: https://github.com/syntax-tree/unist-util-is
201+
202+
[tree]: https://github.com/syntax-tree/unist#tree
203+
204+
[type]: https://github.com/syntax-tree/unist#type
205+
206+
[index]: https://github.com/syntax-tree/unist#index
207+
208+
[heading]: https://github.com/syntax-tree/mdast#heading
209+
210+
[list]: https://github.com/syntax-tree/mdast#list
211+
212+
[blockquote]: https://github.com/syntax-tree/mdast#blockquote
213+
214+
[parents]: #optionsparents

0 commit comments

Comments
 (0)