8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- ** [ hast] [ ] ** utility to truncate the tree to a comment.
11
+ [ hast] [ ] utility to truncate the tree to a comment.
12
12
13
- ## Install
13
+ ## Contents
14
+
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` excerpt(tree, options?) ` ] ( #excerpttree-options )
21
+ * [ Types] ( #types )
22
+ * [ Compatibility] ( #compatibility )
23
+ * [ Security] ( #security )
24
+ * [ Related] ( #related )
25
+ * [ Contribute] ( #contribute )
26
+ * [ License] ( #license )
27
+
28
+ ## What is this?
29
+
30
+ This package is a utility that takes a [ hast] [ ] (HTML) syntax tree and truncates
31
+ it to a comment, while otherwise preserving the tree structure.
14
32
15
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
16
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
33
+ ## When should I use this?
17
34
18
- [ npm] [ ] :
35
+ This is a small utility useful when you need to create a shorter version of a
36
+ potentially long document, and want authors to be able to mark where that
37
+ version ends.
38
+
39
+ This utility is similar to [ ` hast-util-truncate ` ] [ hast-util-truncate ] , which
40
+ truncates a tree to a certain number of characters.
41
+
42
+ The rehype plugin
43
+ [ ` rehype-infer-description-meta ` ] [ rehype-infer-description-meta ]
44
+ wraps both this utility and ` hast-util-truncate ` to figure out a description of
45
+ a document, for use with [ ` rehype-meta ` ] [ rehype-meta ] .
46
+
47
+ ## Install
48
+
49
+ This package is [ ESM only] [ esm ] .
50
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
19
51
20
52
``` sh
21
53
npm install hast-util-excerpt
22
54
```
23
55
56
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
57
+
58
+ ``` js
59
+ import {excerpt } from " https://esm.sh/hast-util-excerpt@1"
60
+ ```
61
+
62
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
63
+
64
+ ``` html
65
+ <script type =" module" >
66
+ import {excerpt } from " https://esm.sh/hast-util-excerpt@1?bundle"
67
+ </script >
68
+ ```
69
+
24
70
## Use
25
71
26
- Say we have the following module, ` example.js ` :
72
+ Say our module ` example.js ` looks as follows :
27
73
28
74
``` js
29
75
import {u } from ' unist-builder'
@@ -41,7 +87,7 @@ const tree = h('p', [
41
87
console .log (excerpt (tree));
42
88
```
43
89
44
- Now, running ` node example.js ` yields:
90
+ …now running ` node example.js ` yields:
45
91
46
92
``` js
47
93
{
@@ -67,13 +113,17 @@ Now, running `node example.js` yields:
67
113
68
114
## API
69
115
70
- This package exports the following identifiers: ` excerpt ` .
116
+ This package exports the identifier ` excerpt ` .
71
117
There is no default export.
72
118
73
119
### ` excerpt(tree, options?) `
74
120
75
121
Truncate the tree to a comment.
76
122
123
+ ##### ` options `
124
+
125
+ Configuration (optional).
126
+
77
127
###### ` options.comment `
78
128
79
129
Comment value to search for (` string ` , default: ` 'more' ` ).
@@ -93,23 +143,39 @@ These are not counted towards `size`.
93
143
94
144
###### Returns
95
145
96
- ` Node? ` — Truncated copy of ` tree ` if there’s a comment, ` undefined ` otherwise.
146
+ Truncated copy of ` tree ` if there’s a comment, ` undefined ` otherwise (` Node? ` ).
147
+
148
+ ## Types
149
+
150
+ This package is fully typed with [ TypeScript] [ ] .
151
+ It exports the additional type ` Options ` .
152
+
153
+ ## Compatibility
154
+
155
+ Projects maintained by the unified collective are compatible with all maintained
156
+ versions of Node.js.
157
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
158
+ Our projects sometimes work with older versions, but this is not guaranteed.
97
159
98
160
## Security
99
161
100
162
Use of ` hast-util-excerpt ` should be safe if the tree is already safe and
101
163
you’re not using user content in options.
102
- When in doubt, use [ ` hast-util-sanitize ` ] [ sanitize ] .
164
+ When in doubt, use [ ` hast-util-sanitize ` ] [ hast-util- sanitize] .
103
165
104
166
## Related
105
167
106
168
* [ ` hast-util-truncate ` ] ( https://github.com/syntax-tree/hast-util-truncate )
107
- — Truncate the tree to a certain number of characters
169
+ — truncate the tree to a number of characters
170
+ * [ ` rehype-infer-description-meta ` ] [ rehype-infer-description-meta ]
171
+ — infer file metadata from the contents of the document
172
+ * [ ` rehype-meta ` ] [ rehype-meta ]
173
+ — add metadata to the head of a document
108
174
109
175
## Contribute
110
176
111
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
112
- started.
177
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
178
+ ways to get started.
113
179
See [ ` support.md ` ] [ support ] for ways to get help.
114
180
115
181
This project has a [ code of conduct] [ coc ] .
@@ -150,16 +216,30 @@ abide by its terms.
150
216
151
217
[ npm ] : https://docs.npmjs.com/cli/install
152
218
219
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
220
+
221
+ [ esmsh ] : https://esm.sh
222
+
223
+ [ typescript ] : https://www.typescriptlang.org
224
+
153
225
[ license ] : license
154
226
155
227
[ author ] : https://wooorm.com
156
228
157
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
229
+ [ health ] : https://github.com/syntax-tree/.github
158
230
159
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
231
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
160
232
161
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct .md
233
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support .md
162
234
163
- [ sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
235
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
164
236
165
237
[ hast ] : https://github.com/syntax-tree/hast
238
+
239
+ [ hast-util-sanitize ] : https://github.com/syntax-tree/hast-util-sanitize
240
+
241
+ [ hast-util-truncate ] : https://github.com/syntax-tree/hast-util-truncate
242
+
243
+ [ rehype-infer-description-meta ] : https://github.com/rehypejs/rehype-infer-description-meta
244
+
245
+ [ rehype-meta ] : https://github.com/rehypejs/rehype-meta
0 commit comments