|
17 | 17 | * [Install](#install)
|
18 | 18 | * [Use](#use)
|
19 | 19 | * [API](#api)
|
20 |
| - * [`excerpt(tree, options?)`](#excerpttree-options) |
| 20 | + * [`excerpt(tree[, options])`](#excerpttree-options) |
| 21 | + * [`Options`](#options) |
| 22 | +* [Syntax tree](#syntax-tree) |
21 | 23 | * [Types](#types)
|
22 | 24 | * [Compatibility](#compatibility)
|
23 | 25 | * [Security](#security)
|
@@ -47,7 +49,7 @@ a document, for use with [`rehype-meta`][rehype-meta].
|
47 | 49 | ## Install
|
48 | 50 |
|
49 | 51 | This package is [ESM only][esm].
|
50 |
| -In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: |
| 52 | +In Node.js (version 14.14+ or 16.0+), install with [npm][]: |
51 | 53 |
|
52 | 54 | ```sh
|
53 | 55 | npm install hast-util-excerpt
|
@@ -113,48 +115,62 @@ console.log(excerpt(tree));
|
113 | 115 |
|
114 | 116 | ## API
|
115 | 117 |
|
116 |
| -This package exports the identifier `excerpt`. |
| 118 | +This package exports the identifier [`excerpt`][excerpt]. |
117 | 119 | There is no default export.
|
118 | 120 |
|
119 |
| -### `excerpt(tree, options?)` |
| 121 | +### `excerpt(tree[, options])` |
120 | 122 |
|
121 |
| -Truncate the tree to a comment. |
| 123 | +Truncate `tree` to a certain comment. |
122 | 124 |
|
123 |
| -##### `options` |
| 125 | +###### Parameters |
124 | 126 |
|
125 |
| -Configuration (optional). |
| 127 | +* `tree` ([`Node`][node]) |
| 128 | + — tree to truncate |
| 129 | +* `options` ([`Options`][options]) |
| 130 | + — configuration (optional) |
126 | 131 |
|
127 |
| -###### `options.comment` |
| 132 | +###### Returns |
| 133 | + |
| 134 | +Truncated copy of `tree` ([`Node`][node]) when a comment is found, `undefined` |
| 135 | +otherwise. |
| 136 | + |
| 137 | +### `Options` |
| 138 | + |
| 139 | +Configuration (TypeScript type). |
| 140 | + |
| 141 | +##### Fields |
| 142 | + |
| 143 | +###### `comment` |
128 | 144 |
|
129 | 145 | Comment value to search for (`string`, default: `'more'`).
|
130 | 146 |
|
131 |
| -###### `options.maxSearchSize` |
| 147 | +###### `maxSearchSize` |
132 | 148 |
|
133 | 149 | How far to search for the comment before bailing (`number`, default: `2048`).
|
134 | 150 | The goal of this project is to find user-defined explicit excerpts, that are
|
135 | 151 | assumed to be somewhat reasonably placed.
|
136 | 152 | This option prevents searching giant documents for some comment that probably
|
137 | 153 | won’t be found at the end.
|
138 | 154 |
|
139 |
| -###### `options.ignore` |
| 155 | +###### `ignore` |
140 | 156 |
|
141 |
| -Nodes to exclude from the resulting tree (`Array<Node>`). |
| 157 | +Nodes to exclude from the resulting tree ([`Array<Node>`][node]). |
142 | 158 | These are not counted towards `size`.
|
143 | 159 |
|
144 |
| -###### Returns |
| 160 | +## Syntax tree |
145 | 161 |
|
146 |
| -Truncated copy of `tree` if there’s a comment, `undefined` otherwise (`Node?`). |
| 162 | +The syntax tree is [hast][]. |
147 | 163 |
|
148 | 164 | ## Types
|
149 | 165 |
|
150 | 166 | This package is fully typed with [TypeScript][].
|
151 |
| -It exports the additional type `Options`. |
| 167 | +It exports the additional type [`Options`][options]. |
152 | 168 |
|
153 | 169 | ## Compatibility
|
154 | 170 |
|
155 | 171 | Projects maintained by the unified collective are compatible with all maintained
|
156 | 172 | versions of Node.js.
|
157 |
| -As of now, that is Node.js 12.20+, 14.14+, and 16.0+. |
| 173 | +As of now, that is Node.js 14.14+ and 16.0+. |
158 | 174 | Our projects sometimes work with older versions, but this is not guaranteed.
|
159 | 175 |
|
160 | 176 | ## Security
|
@@ -243,3 +259,9 @@ abide by its terms.
|
243 | 259 | [rehype-infer-description-meta]: https://github.com/rehypejs/rehype-infer-description-meta
|
244 | 260 |
|
245 | 261 | [rehype-meta]: https://github.com/rehypejs/rehype-meta
|
| 262 | + |
| 263 | +[excerpt]: #excerpttree-options |
| 264 | + |
| 265 | +[options]: #options |
| 266 | + |
| 267 | +[node]: https://github.com/syntax-tree/hast#nodes |
0 commit comments