File tree Expand file tree Collapse file tree 2 files changed +18
-16
lines changed Expand file tree Collapse file tree 2 files changed +18
-16
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
- * @typedef {import('unist').Node } UnistNode
3
- * @typedef {import('hast').Element } HastElement
4
- * @typedef {import('unist-util-visit').Visitor<HastElement> } VisitElement
2
+ * @typedef {Root['children'][number]|Root } Node
3
+ * @typedef {import('hast').Root } Root
4
+ * @typedef {import('hast').Element } Element
5
+ * @typedef {import('unist-util-visit').Visitor<Element> } VisitElement
5
6
*/
6
7
7
8
import { headingRank } from 'hast-util-heading-rank'
8
9
import { visit } from 'unist-util-visit'
9
10
10
11
/**
11
- * @template {UnistNode } T
12
+ * @template {Node } T
12
13
* @param {T } tree
13
14
* @param {number } shift
14
15
* @returns {T }
@@ -23,17 +24,19 @@ export function shiftHeading(tree, shift) {
23
24
throw new Error ( 'Expected a non-null finite integer, not `' + shift + '`' )
24
25
}
25
26
26
- visit ( tree , 'element' , visitor )
27
+ visit (
28
+ tree ,
29
+ 'element' ,
30
+ /** @type {VisitElement } */
31
+ ( node ) => {
32
+ let rank = headingRank ( node )
27
33
28
- return tree
29
-
30
- /** @type {VisitElement } */
31
- function visitor ( node ) {
32
- let rank = headingRank ( node )
33
-
34
- if ( rank ) {
35
- rank += shift
36
- node . tagName = 'h' + ( rank > 6 ? 6 : rank < 1 ? 1 : rank )
34
+ if ( rank ) {
35
+ rank += shift
36
+ node . tagName = 'h' + ( rank > 6 ? 6 : rank < 1 ? 1 : rank )
37
+ }
37
38
}
38
- }
39
+ )
40
+
41
+ return tree
39
42
}
Original file line number Diff line number Diff line change 37
37
],
38
38
"dependencies" : {
39
39
"@types/hast" : " ^2.0.0" ,
40
- "@types/unist" : " ^2.0.0" ,
41
40
"hast-util-heading-rank" : " ^2.0.0" ,
42
41
"unist-util-visit" : " ^3.0.0"
43
42
},
You can’t perform that action at this time.
0 commit comments