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 11'use strict'
22
3+ var headingRank = require ( 'hast-util-heading-rank' )
34var visit = require ( 'unist-util-visit' )
45
56module . exports = shiftHeading
@@ -14,23 +15,15 @@ function shiftHeading(tree, shift) {
1415 throw new Error ( 'Expected a non-null finite integer, not `' + shift + '`' )
1516 }
1617
17- visit ( tree , visitor )
18+ visit ( tree , 'element' , visitor )
1819
1920 return tree
2021
2122 function visitor ( node ) {
22- var name = node . tagName
23- var rank
23+ var rank = headingRank ( node )
2424
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
3427 node . tagName = 'h' + ( rank > 6 ? 6 : rank < 1 ? 1 : rank )
3528 }
3629 }
Original file line number Diff line number Diff line change 3131 " index.js"
3232 ],
3333 "dependencies" : {
34+ "hast-util-heading-rank" : " ^1.0.0" ,
3435 "unist-util-visit" : " ^2.0.0"
3536 },
3637 "devDependencies" : {
You can’t perform that action at this time.
0 commit comments