Skip to content

Commit b2e0058

Browse files
javiereguiluzweaverryan
authored andcommitted
Fixed the generation of TOCs
1 parent a90dd3b commit b2e0058

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Twig/TocExtension.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@ public function getFunctions(): array
2424
public static function getOptions(array $toc): array
2525
{
2626
$flattendToc = self::flattenToc($toc);
27-
$maxDepth = 0;
27+
// FIXME: this hardcoded '2' value should instead be obtained
28+
// automatically using the 'maxdepth' option of 'toctree' directive.
29+
// See https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html
30+
$maxDepth = 2;
2831
$numVisibleItems = 0;
2932
foreach ($flattendToc as $tocItem) {
30-
$maxDepth = max($maxDepth, $tocItem['level']);
33+
if ($tocItem['level'] > $maxDepth) {
34+
continue;
35+
}
36+
3137
$numVisibleItems++;
3238
}
3339

0 commit comments

Comments
 (0)