Skip to content

Commit 9814e0c

Browse files
committed
bug #102 Fixed the generation of TOCs (javiereguiluz)
This PR was squashed before being merged into the main branch. Discussion ---------- Fixed the generation of TOCs In some private tests we saw that a short TOC was displayed in two columns (as if it was a long TOC) whereas a slightly longer TOC was displayed in a single column. The reason is that we were counting all TOC elements, instead of only the visible elements. Please note that this PR is almost, but not entirely, correct. I had to hardcode the number of visible TOC levels at `2` (by far, the most common value in Symfony-related docs) but this should instead be obtained dynamically via the `maxdepth` TOC tree option in the RST contents. Commits ------- b2e0058 Fixed the generation of TOCs
2 parents 8e85fb8 + b2e0058 commit 9814e0c

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)