@@ -4,18 +4,18 @@ module.exports = search
44
55var toString = require ( 'mdast-util-to-string' )
66var visit = require ( 'unist-util-visit' )
7- var is = require ( 'unist-util-is' )
7+ var convert = require ( 'unist-util-is/convert ' )
88var slugs = require ( 'github-slugger' ) ( )
99
10- var HEADING = 'heading'
10+ var heading = convert ( 'heading' )
1111
1212// Search a node for a location.
1313function search ( root , expression , settings ) {
1414 var length = root . children . length
1515 var depth = null
1616 var lookingForToc = expression !== null
1717 var maxDepth = settings . maxDepth || 6
18- var parents = settings . parents || root
18+ var parents = convert ( settings . parents || root )
1919 var map = [ ]
2020 var headingIndex
2121 var closingIndex
@@ -28,7 +28,7 @@ function search(root, expression, settings) {
2828
2929 // Visit all headings in `root`. We `slug` all headings (to account for
3030 // duplicates), but only create a TOC from top-level headings.
31- visit ( root , HEADING , onheading )
31+ visit ( root , 'heading' , onheading )
3232
3333 if ( headingIndex && ! closingIndex ) {
3434 closingIndex = length + 1
@@ -46,7 +46,7 @@ function search(root, expression, settings) {
4646 var value = toString ( child )
4747 var id = child . data && child . data . hProperties && child . data . hProperties . id
4848
49- if ( ! is ( parents , parent ) ) {
49+ if ( ! parents ( parent ) ) {
5050 return
5151 }
5252
@@ -74,15 +74,10 @@ function search(root, expression, settings) {
7474
7575// Check if `node` is the main heading.
7676function 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 ) )
8378}
8479
8580// Check if `node` is the next heading.
8681function isClosingHeading ( node , depth ) {
87- return depth && node && node . type === HEADING && node . depth <= depth
82+ return depth && heading ( node ) && node . depth <= depth
8883}
0 commit comments