function updateToc(headingsArray) {
        // If a fixed content container was set
        if (options.scrollContainer && document.querySelector(options.scrollContainer)) {
            var top
            top = document.querySelector(options.scrollContainer).scrollTop
        } else {
            top = document.documentElement.scrollTop || body.scrollTop
        }

        // Add fixed class at offset
        if (options.positionFixedSelector) {
            updateFixedSidebarClass()
        }

        // Get the top most heading currently visible on the page so we know what to highlight.
        var headings = headingsArray
        var topHeader
        // Using some instead of each so that we can escape early.
        if (currentlyHighlighting &&
            tocElement !== null &&
            headings.length > 0) {
            some.call(headings, function (heading, i) {
                var modifiedTopOffset = top + 10
                if (mainContainer) {
                    modifiedTopOffset += mainContainer.clientHeight * (mainContainer.scrollTop) / (mainContainer.scrollHeight - mainContainer.clientHeight)
                }
                if (getHeadingTopPos(heading) > modifiedTopOffset) {
                    // Don't allow negative index value.
                    var index = (i === 0) ? i : i - 1
                    topHeader = headings[index]
                    return true
                } else if (i === headings.length - 1) {
                    // This allows scrolling for the last heading on the page.
                    topHeader = headings[headings.length - 1]
                    return true
                }
            })

            // Remove the active class from the other tocLinks.
            updateListActiveElement(topHeader)
        }
    }
Update TOC highlighting and collpased groupings.