summaryrefslogtreecommitdiff
path: root/sphinx/directives/other.py
diff options
context:
space:
mode:
authorBrecht Machiels <brecht@mos6581.org>2022-09-12 21:13:14 +0200
committerGitHub <noreply@github.com>2022-09-12 20:13:14 +0100
commitd924acfdb98a91f628aed8dc44d07d9309e6f9b6 (patch)
tree193f4c3a4d855c263304f516d3a8d8342000c65f /sphinx/directives/other.py
parentc8e5199cc9083316a0da358ebfce42d8c58fdcc4 (diff)
downloadsphinx-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/directives/other.py')
-rw-r--r--sphinx/directives/other.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py
index 35e16e623..fa8fc191a 100644
--- a/sphinx/directives/other.py
+++ b/sphinx/directives/other.py
@@ -77,10 +77,11 @@ class TocTree(SphinxDirective):
return ret
def parse_content(self, toctree: addnodes.toctree) -> List[Node]:
+ generated_docnames = frozenset(self.env.domains['std'].initial_data['labels'].keys())
suffixes = self.config.source_suffix
# glob target documents
- all_docnames = self.env.found_docs.copy()
+ all_docnames = self.env.found_docs.copy() | generated_docnames
all_docnames.remove(self.env.docname) # remove current document
ret: List[Node] = []
@@ -95,6 +96,9 @@ class TocTree(SphinxDirective):
patname = docname_join(self.env.docname, entry)
docnames = sorted(patfilter(all_docnames, patname))
for docname in docnames:
+ if docname in generated_docnames:
+ # don't include generated documents in globs
+ continue
all_docnames.remove(docname) # don't include it again
toctree['entries'].append((None, docname))
toctree['includefiles'].append(docname)
@@ -118,7 +122,7 @@ class TocTree(SphinxDirective):
docname = docname_join(self.env.docname, docname)
if url_re.match(ref) or ref == 'self':
toctree['entries'].append((title, ref))
- elif docname not in self.env.found_docs:
+ elif docname not in self.env.found_docs | generated_docnames:
if excluded(self.env.doc2path(docname, False)):
message = __('toctree contains reference to excluded document %r')
subtype = 'excluded'