From 0884f20230efe6c80825f7ffefa86127fe23e84e Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 1 Aug 2024 12:00:25 +0200 Subject: [PATCH] Slightly simplify toctree code While working on #12720, I noticed that `parse_content` creates and returns an empty node list. It does not do anything with it. This PR moves the node out of `parse_content`, so that `parse_content` only populates the toctree entries. The complete node creation logic is now united in `TocTree.run`. --- sphinx/directives/other.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index f74f919cc3e..e4da8e4d323 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -78,17 +78,19 @@ def run(self) -> list[Node]: subnode['numbered'] = self.options.get('numbered', 0) subnode['titlesonly'] = 'titlesonly' in self.options self.set_source_info(subnode) + self.parse_content(subnode) + wrappernode = nodes.compound( classes=['toctree-wrapper', *self.options.get('class', ())], ) wrappernode.append(subnode) self.add_name(wrappernode) + return [wrappernode] - ret = self.parse_content(subnode) - ret.append(wrappernode) - return ret - - def parse_content(self, toctree: addnodes.toctree) -> list[Node]: + def parse_content(self, toctree: addnodes.toctree): + """ + Populate ``toctree['entries']`` and ``toctree['includefiles']`` from content. + """ generated_docnames = frozenset(StandardDomain._virtual_doc_names) suffixes = self.config.source_suffix current_docname = self.env.docname @@ -170,8 +172,6 @@ def parse_content(self, toctree: addnodes.toctree) -> list[Node]: toctree['entries'] = list(reversed(toctree['entries'])) toctree['includefiles'] = list(reversed(toctree['includefiles'])) - return ret - class Author(SphinxDirective): """