8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** hast** ] [ hast ] utility to change the rank ( depth, level) of headings.
11
+ [ hast] [ ] utility to change ranks (also knows as depth or level) of headings.
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
+ * [ ` shiftHeading(tree, shift) ` ] ( #shiftheadingtree-shift )
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 small utility that rewrites heading ranks relative to a
31
+ number.
32
+
33
+ ## When should I use this?
34
+
35
+ You can use this package when you have some content, say an article that starts
36
+ with an ` h1 ` , but want to display it on a page that uses for example an ` h1 `
37
+ already as the website name (logo?).
14
38
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 .
39
+ You can use the package [ ` hast-util-heading-rank ` ] [ hast-util-heading-rank ]
40
+ to get the rank of an element .
17
41
18
- [ npm] [ ] :
42
+ ## Install
43
+
44
+ This package is [ ESM only] [ esm ] .
45
+ In Node.js (version 12.20+, 14.14+, 16.0+, or 18.0+), install with [ npm] [ ] :
19
46
20
47
``` sh
21
48
npm install hast-util-shift-heading
22
49
```
23
50
51
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
52
+
53
+ ``` js
54
+ import {shiftHeading } from ' https://esm.sh/hast-util-shift-heading@3'
55
+ ```
56
+
57
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
58
+
59
+ ``` html
60
+ <script type =" module" >
61
+ import {shiftHeading } from ' https://esm.sh/hast-util-shift-heading@3?bundle'
62
+ </script >
63
+ ```
64
+
24
65
## Use
25
66
26
67
``` js
@@ -81,28 +122,40 @@ Yields:
81
122
82
123
## API
83
124
84
- This package exports the following identifiers: ` shiftHeading ` .
125
+ This package exports the identifier ` shiftHeading ` .
85
126
There is no default export.
86
127
87
128
### ` shiftHeading(tree, shift) `
88
129
89
130
Change the rank of all headings (` h1 ` to ` h6 ` ) in ` tree ` .
90
131
Mutates the tree.
91
- Caps the rank so that shifting would not create invalid headings (such as ` h0 `
92
- or ` h7 ` ).
132
+ Caps the rank so that shifting would not create invalid headings (so no ` h0 ` or
133
+ ` h7 ` ).
93
134
94
135
###### Parameters
95
136
96
- * ` tree ` ([ ` Node ` ] [ node ] ) — [ * Tree * ] [ tree ] to walk
97
- * ` shift ` (` number ` ) — Non -null finite integer to use to shift ranks
137
+ * ` tree ` ([ ` Node ` ] [ node ] ) — tree to walk
138
+ * ` shift ` (` number ` ) — non -null finite integer to use to shift ranks
98
139
99
140
###### Returns
100
141
101
- ` tree ` ([ ` Node ` ] [ node ] ) — The given, mutated, tree .
142
+ The given, mutated, tree ([ ` Node ` ] [ node ] ).
102
143
103
144
###### Throws
104
145
105
- ` Error ` — When ` shift ` is not a valid non-null finite integer.
146
+ When ` shift ` is not a valid non-null finite integer.
147
+
148
+ ## Types
149
+
150
+ This package is fully typed with [ TypeScript] [ ] .
151
+ It exports no additional types.
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+, 16.0+, and 18.0+.
158
+ Our projects sometimes work with older versions, but this is not guaranteed.
106
159
107
160
## Security
108
161
@@ -113,14 +166,14 @@ There are no openings for [cross-site scripting (XSS)][xss] attacks.
113
166
## Related
114
167
115
168
* [ ` hast-util-heading ` ] ( https://github.com/syntax-tree/hast-util-heading )
116
- — check if a node is a heading element
169
+ — check if a node is heading content
117
170
* [ ` hast-util-heading-rank ` ] ( https://github.com/syntax-tree/hast-util-heading-rank )
118
171
— get the rank (or depth, level) of headings
119
172
120
173
## Contribute
121
174
122
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
123
- started.
175
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
176
+ ways to get started.
124
177
See [ ` support.md ` ] [ support ] for ways to get help.
125
178
126
179
This project has a [ code of conduct] [ coc ] .
@@ -161,20 +214,28 @@ abide by its terms.
161
214
162
215
[ npm ] : https://docs.npmjs.com/cli/install
163
216
217
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
218
+
219
+ [ esmsh ] : https://esm.sh
220
+
221
+ [ typescript ] : https://www.typescriptlang.org
222
+
164
223
[ license ] : license
165
224
166
225
[ author ] : https://wooorm.com
167
226
168
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
227
+ [ health ] : https://github.com/syntax-tree/.github
169
228
170
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support .md
229
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing .md
171
230
172
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct .md
231
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support .md
173
232
174
- [ tree ] : https://github.com/syntax-tree/unist#tree
233
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
175
234
176
235
[ hast ] : https://github.com/syntax-tree/hast
177
236
178
237
[ node ] : https://github.com/syntax-tree/hast#nodes
179
238
239
+ [ hast-util-heading-rank ] : https://github.com/syntax-tree/hast-util-heading-rank
240
+
180
241
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
0 commit comments