Use the maxdepth option of the toctree directive to count the visible TOC items#207
Open
Amoifr wants to merge 2 commits into
Open
Use the maxdepth option of the toctree directive to count the visible TOC items#207Amoifr wants to merge 2 commits into
Amoifr wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #106, which tracked the
FIXMEleft behind in #102:Good news: everything needed was already there.
TocNode::getDepth()reads the directive'smaxdepthoption (falling back to2), andTocNodeRendereralready passestocNodetotoc.html.twig— it just wasn't being used. Sotoc_options()now takes the depth as an argument:{% set toc_options = toc_options(tocItems, tocNode.depth) %}What was actually broken: with
:maxdepth: 3or more, the deeper items are rendered but were not counted as visible, sonumVisibleItemswas too low and the TOC got the wrongtoc-size-*class — i.e. the wrong number of columns. That is exactly the symptom described in #102. A toctree with:maxdepth: 1or2is unaffected, since the renderer never builds items below the depth anyway.The parameter defaults to
2, soJsonGenerator— whose TOC is crawled fromh2/h3and therefore only ever has levels 1 and 2 — keeps behaving exactly as before.Tests:
TocExtensionpinning the count per depth (2 items on level 1, 4 on level 2, 8 on level 3 → 2 / 6 / 14 visible for maxdepth 1 / 2 / 3), plus the default;toctree-maxdepth) with a:maxdepth: 3toctree, sized so the bug is visible: 6 counted items before (toc-size-md), 14 after (toc-size-lg).I checked the fixture actually fails without the fix — it reports
toc-size-lgexpected,toc-size-mdgiven. Full suite green: 79 tests, 176 assertions (74 before).Thanks for the tool — the docs wouldn't build without it. 🙂