protected function addTocEntries(IndexPage $index)
 {
     foreach ($index->getChildren() as $child) {
         $headings = $child->getHeadings();
         foreach ($headings as $heading) {
             $this->tocEntries[] = $heading;
         }
         if ($child->isIndex()) {
             $this->addTocEntries($child);
         }
     }
 }
 /**
  * A toc depth of 0 means render all headings. A toc depth of 1 is a special case
  *
  * @param IndexPage $index
  * @param $tocDepth
  * @param int $level
  */
 protected function addTocEntries(IndexPage $index, $tocDepth, $level = 0)
 {
     $maxLevel = $level + $tocDepth;
     if ($tocDepth !== 1 && $tocDepth && $index->isRoot()) {
         $maxLevel--;
     }
     foreach ($index->getChildren() as $child) {
         $headings = $child->getHeadings();
         foreach ($headings as $heading) {
             if ($tocDepth && $heading->getLevel() > $maxLevel) {
                 continue;
             }
             $this->tocEntries[] = $heading;
         }
         if ($child->isIndex() && $tocDepth !== 1) {
             $this->addTocEntries($child, $tocDepth, $index->isRoot() ? $level : $level + 1);
         }
     }
 }