Skip to content

Commit

Permalink
Slightly simplify toctree code (#12724)
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm authored Aug 9, 2024
1 parent 4f270a5 commit d40840e
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions sphinx/directives/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> None:
"""
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
Expand All @@ -99,7 +101,6 @@ def parse_content(self, toctree: addnodes.toctree) -> list[Node]:
all_docnames.remove(current_docname) # remove current document
frozen_all_docnames = frozenset(all_docnames)

ret: list[Node] = []
excluded = Matcher(self.config.exclude_patterns)
for entry in self.content:
if not entry:
Expand Down Expand Up @@ -170,8 +171,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):
"""
Expand Down

0 comments on commit d40840e

Please sign in to comment.