diff --git a/src/Twig/TocExtension.php b/src/Twig/TocExtension.php index ebea8c8..f8bcf8a 100644 --- a/src/Twig/TocExtension.php +++ b/src/Twig/TocExtension.php @@ -24,10 +24,16 @@ public function getFunctions(): array public static function getOptions(array $toc): array { $flattendToc = self::flattenToc($toc); - $maxDepth = 0; + // FIXME: this hardcoded '2' value should instead be obtained + // automatically using the 'maxdepth' option of 'toctree' directive. + // See https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html + $maxDepth = 2; $numVisibleItems = 0; foreach ($flattendToc as $tocItem) { - $maxDepth = max($maxDepth, $tocItem['level']); + if ($tocItem['level'] > $maxDepth) { + continue; + } + $numVisibleItems++; }