File tree Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Expand file tree Collapse file tree 2 files changed +6
-12
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ var headingRank = require ( 'hast-util-heading-rank' )
3
4
var visit = require ( 'unist-util-visit' )
4
5
5
6
module . exports = shiftHeading
@@ -14,23 +15,15 @@ function shiftHeading(tree, shift) {
14
15
throw new Error ( 'Expected a non-null finite integer, not `' + shift + '`' )
15
16
}
16
17
17
- visit ( tree , visitor )
18
+ visit ( tree , 'element' , visitor )
18
19
19
20
return tree
20
21
21
22
function visitor ( node ) {
22
- var name = node . tagName
23
- var rank
23
+ var rank = headingRank ( node )
24
24
25
- if (
26
- name === 'h1' ||
27
- name === 'h2' ||
28
- name === 'h3' ||
29
- name === 'h4' ||
30
- name === 'h5' ||
31
- name === 'h6'
32
- ) {
33
- rank = name . charCodeAt ( 1 ) - 48 /* `0` */ + shift
25
+ if ( rank ) {
26
+ rank += shift
34
27
node . tagName = 'h' + ( rank > 6 ? 6 : rank < 1 ? 1 : rank )
35
28
}
36
29
}
Original file line number Diff line number Diff line change 31
31
" index.js"
32
32
],
33
33
"dependencies" : {
34
+ "hast-util-heading-rank" : " ^1.0.0" ,
34
35
"unist-util-visit" : " ^2.0.0"
35
36
},
36
37
"devDependencies" : {
You can’t perform that action at this time.
0 commit comments