protected function visitSection(\DOMNode $root, \ezcDocumentRstNode $node)
    {
        if ($node instanceof ezcDocumentRstSectionNode || $node instanceof ezcDocumentRstDocumentNode) {
            if ($node->depth === 1) {
                $toc = $this->getTableOfContents();
                $file = $toc[$this->getFilenameWithoutExtension()];
                $file->setName($this->nodeToString($node->title));
            } else {
                // find nearest parent pointer depth-wise
                $parent_depth = $node->depth - 1;
                while (!isset($this->entry_pointers[$parent_depth]) && $parent_depth > 0) {
                    --$parent_depth;
                }

                $parent = $this->entry_pointers[$parent_depth];
                $heading = new TableOfContents\Heading($parent);
                $heading->setName($this->nodeToString($node->title));
                $heading->setSlug($node->reference);
                $parent->addChild($heading);

                // set as last indexed heading
                $this->last_heading = $heading;

                // add as new entry pointer
                array_splice($this->entry_pointers, $parent_depth + 1, count($this->entry_pointers), [$heading]);
            }
        }

        parent::visitSection($root, $node);
    }