Skip to content

Commit

Permalink
Fix recursion error when nested toctrees contain a self entry
Browse files Browse the repository at this point in the history
  • Loading branch information
TDKorn committed Feb 4, 2024
1 parent 52447e1 commit 2212e84
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sphinx_readme/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,18 @@ def _parse_toctree(self, toctree, docname, tocs, is_subtoc=False):
toc['maxdepth'] = toctree.get('maxdepth')

for text, entry in toctree.get('entries', []):
entry = entry if entry != 'self' else docname
title = text if text else self.titles.get(entry)
subtree = tocs[entry].next_node(nodes.bullet_list)
entry_name = entry if entry != 'self' else docname
title = text if text else self.titles.get(entry_name)
subtree = tocs[entry_name].next_node(nodes.bullet_list)

if subtree:
if subtree and entry != 'self':
if is_subtoc or 'maxdepth' in toc:
subtree = self._parse_subtree(subtree, tocs)
else:
subtree = None # Sphinx treats "self" as titlesonly

toc['entries'].append({
'entry': entry,
'entry': entry_name,
'title': title,
'entries': subtree
})
Expand All @@ -359,8 +361,9 @@ def _parse_subtree(self, tree: nodes.bullet_list, tocs: Dict[str, nodes.bullet_l

for child in tree.children:
if isinstance(child, addnodes.toctree):
child_doc = Path(child.source).relative_to(self.config.src_dir)
sub_toc = self._parse_toctree(
docname=Path(child.source).stem,
docname=child_doc.as_posix().removesuffix(child_doc.suffix),
is_subtoc=True, tocs=tocs,
toctree=child,
)
Expand Down

0 comments on commit 2212e84

Please sign in to comment.