@@ -4,18 +4,18 @@ module.exports = search
4
4
5
5
var toString = require ( 'mdast-util-to-string' )
6
6
var visit = require ( 'unist-util-visit' )
7
- var is = require ( 'unist-util-is' )
7
+ var convert = require ( 'unist-util-is/convert ' )
8
8
var slugs = require ( 'github-slugger' ) ( )
9
9
10
- var HEADING = 'heading'
10
+ var heading = convert ( 'heading' )
11
11
12
12
// Search a node for a location.
13
13
function search ( root , expression , settings ) {
14
14
var length = root . children . length
15
15
var depth = null
16
16
var lookingForToc = expression !== null
17
17
var maxDepth = settings . maxDepth || 6
18
- var parents = settings . parents || root
18
+ var parents = convert ( settings . parents || root )
19
19
var map = [ ]
20
20
var headingIndex
21
21
var closingIndex
@@ -28,7 +28,7 @@ function search(root, expression, settings) {
28
28
29
29
// Visit all headings in `root`. We `slug` all headings (to account for
30
30
// duplicates), but only create a TOC from top-level headings.
31
- visit ( root , HEADING , onheading )
31
+ visit ( root , 'heading' , onheading )
32
32
33
33
if ( headingIndex && ! closingIndex ) {
34
34
closingIndex = length + 1
@@ -46,7 +46,7 @@ function search(root, expression, settings) {
46
46
var value = toString ( child )
47
47
var id = child . data && child . data . hProperties && child . data . hProperties . id
48
48
49
- if ( ! is ( parents , parent ) ) {
49
+ if ( ! parents ( parent ) ) {
50
50
return
51
51
}
52
52
@@ -74,15 +74,10 @@ function search(root, expression, settings) {
74
74
75
75
// Check if `node` is the main heading.
76
76
function isOpeningHeading ( node , depth , expression ) {
77
- return (
78
- depth === null &&
79
- node &&
80
- node . type === HEADING &&
81
- expression . test ( toString ( node ) )
82
- )
77
+ return depth === null && heading ( node ) && expression . test ( toString ( node ) )
83
78
}
84
79
85
80
// Check if `node` is the next heading.
86
81
function isClosingHeading ( node , depth ) {
87
- return depth && node && node . type === HEADING && node . depth <= depth
82
+ return depth && heading ( node ) && node . depth <= depth
88
83
}
0 commit comments