From b2e0058bc767c0472d455f5fe924cacfab806ca9 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Fri, 2 Jul 2021 12:35:17 +0200 Subject: [PATCH] Fixed the generation of TOCs --- src/Twig/TocExtension.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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++; }