sphinx-doc / sphinx-doc/sphinx

Allow including nested captions in `toctree` function provided to HTML theme templates

Open
#10,697 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

internals:toctree type:enhancement
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Is your feature request related to a problem? Please describe.
I'm exploring ways to enable more flexible/complex site structures with Sphinx, as part of a Sphinx theme (https://github.com/pradyunsg/lutra/). One of the useful bits of toctree metadata, that Sphinx does not include in the final markup, is all of captions for the not-top-level toctree items.

Currently, without this, certain navigational structures cannot be implemented -- eg: having top-level documents as tabs on the site and having their inner toctrees presented with captions in the sidebar (when that tab is active). Providing the nested toctree captions in the toctree directive would make it possible to implement such navifation structures.

Describe the solution you'd like

Allow specifying a captions_till_depth argument, defaulting to 1, on the toctree context variable that behaves like maxdepth but trims captions instead. The toctree generation code would then be adapted to both (a) generate the toctree captions in the nested bullet list and (b) trim them based on this variable.

Describe alternatives you've considered

  1. Maintaining status quo -- this would prevent themes from providing support for certain kinds of site navigation designs.
  2. Add a include_captions argument to the toctree context variable passed into the theme render context (and, add it to TocTree.get_toctree_for). This will default to False -- preserving the current default behaviour. However, when it is set to True, the final markup will contain the caption nested within the rest of the document.

Additional context

$ git clone https://github.com/pradyun/sphinx-nested-toctree-captions
$ cd sphinx-nested-toctree-captions
$ pip install sphinx-autobuild
$ sphinx-autobuild -b dirhtml . /tmp/build --open-browser

Look at the toctree presented. Note that it does not contain the inner-document's toctrees' captions (Aesthetics and Structural) but does contain the top-level-document's toctree's "Usage" caption. Screenshot of what is generated by alabaster:

Screenshot 2022-07-23 at 12 00 15

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked reproduction repository and inspect Sphinx's toctree context variable and the toctree generation code described in the request. Compare the current output with the nested captions shown in the reproduction. Done means the requested caption-depth behavior is available to HTML theme templates while preserving the existing default behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.