diff options
author | Brecht Machiels <brecht@mos6581.org> | 2022-09-12 21:13:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-12 20:13:14 +0100 |
commit | d924acfdb98a91f628aed8dc44d07d9309e6f9b6 (patch) | |
tree | 193f4c3a4d855c263304f516d3a8d8342000c65f /sphinx/environment/adapters/toctree.py | |
parent | c8e5199cc9083316a0da358ebfce42d8c58fdcc4 (diff) | |
download | sphinx-git-d924acfdb98a91f628aed8dc44d07d9309e6f9b6.tar.gz |
Make toctree accept special docnames (#10673)
The `.. toctree::` directive now supports the reserved special docnames
'genindex', 'modindex', and 'search'.
Co-authored-by: Adam Turner <9087854+aa-turner@users.noreply.github.com>
Diffstat (limited to 'sphinx/environment/adapters/toctree.py')
-rw-r--r-- | sphinx/environment/adapters/toctree.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/sphinx/environment/adapters/toctree.py b/sphinx/environment/adapters/toctree.py index 9678e3c7c..348832efe 100644 --- a/sphinx/environment/adapters/toctree.py +++ b/sphinx/environment/adapters/toctree.py @@ -1,6 +1,6 @@ """Toctree adapter for sphinx.environment.""" -from typing import TYPE_CHECKING, Any, Iterable, List, Optional, cast +from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, cast from docutils import nodes from docutils.nodes import Element, Node @@ -54,6 +54,7 @@ class TocTree: """ if toctree.get('hidden', False) and not includehidden: return None + generated_docnames: Dict[str, Tuple[str, str, str]] = self.env.domains['std'].initial_data['labels'].copy() # NoQA: E501 # For reading the following two helper function, it is useful to keep # in mind the node structure of a toctree (using HTML-like node names @@ -139,6 +140,16 @@ class TocTree: item = nodes.list_item('', para) # don't show subitems toc = nodes.bullet_list('', item) + elif ref in generated_docnames: + docname, _, sectionname = generated_docnames[ref] + if not title: + title = sectionname + reference = nodes.reference('', title, internal=True, + refuri=docname, anchorname='') + para = addnodes.compact_paragraph('', '', reference) + item = nodes.list_item('', para) + # don't show subitems + toc = nodes.bullet_list('', item) else: if ref in parents: logger.warning(__('circular toctree references ' |