BookStack\Repos\PageRepo::getPageNav PHP Method

getPageNav() public method

Parse te headers on the page to get a navigation menu
public getPageNav ( Page $page ) : array
$page BookStack\Page
return array
    public function getPageNav(Page $page)
    {
        if ($page->html == '') {
            return null;
        }
        libxml_use_internal_errors(true);
        $doc = new DOMDocument();
        $doc->loadHTML(mb_convert_encoding($page->html, 'HTML-ENTITIES', 'UTF-8'));
        $xPath = new DOMXPath($doc);
        $headers = $xPath->query("//h1|//h2|//h3|//h4|//h5|//h6");
        if (is_null($headers)) {
            return null;
        }
        $tree = [];
        foreach ($headers as $header) {
            $text = $header->nodeValue;
            $tree[] = ['nodeName' => strtolower($header->nodeName), 'level' => intval(str_replace('h', '', $header->nodeName)), 'link' => '#' . $header->getAttribute('id'), 'text' => strlen($text) > 30 ? substr($text, 0, 27) . '...' : $text];
        }
        return $tree;
    }