function addNode(node, nest) {
        var obj = getHeadingObject(node)
        var level = obj.headingLevel
        var array = nest
        var lastItem = getLastItem(array)
        var lastItemLevel = lastItem
            ? lastItem.headingLevel
            : 0
        var counter = level - lastItemLevel

        while (counter > 0) {
            lastItem = getLastItem(array)
            // Handle case where there are multiple h5+ in a row.
            if (lastItem && level === lastItem.headingLevel) {
                break
            } else if (lastItem && lastItem.children !== undefined) {
                array = lastItem.children
            }
            counter--
        }

        if (level >= options.collapseDepth) {
            obj.isCollapsed = true
        }

        array.push(obj)
        return array
    }
Add a node to the nested array.
@param {Object} node
@param {Array} nest
@return {Array}