code: function search(root, test, skip, callback) {
    var index = -1
    var children = root.children
    var length = children.length
    var depth = null
    var start = null
    var end = null
    var nodes
    var clean
    var child
  
    while (++index < length) {
      child = children[index]
  
      if (closing(child, depth)) {
        end = index
        break
      }
  
      if (opening(child, depth, test)) {
        start = index
        depth = child.depth
      }
    }
  
    if (start !== null) {
      if (end === null) {
        end = length
      }
  
      if (skip) {
        while (end > start) {
          child = children[end - 1]
  
          if (!definition(child)) {
            break
          }
  
          end--
        }
      }
  
      nodes = callback(
        children[start],
        children.slice(start + 1, end),
        children[end],
        {
          parent: root,
          start: start,
          end: children[end] ? end : null
        }
      )
  
      clean = []
      index = -1
      length = nodes && nodes.length
  
      // Ensure no empty nodes are inserted.  This could be the case if `end` is
      // in `nodes` but no `end` node exists.
      while (++index < length) {
        if (nodes[index]) {
          clean.push(nodes[index])
        }
      }
  
      if (nodes) {
        splice.apply(children, [start, end - start + 1].concat(clean))
      }
    }
  }
docs: Search a node for heading range.