@@ -339,16 +339,18 @@ def _parse_toctree(self, toctree, docname, tocs, is_subtoc=False):
339
339
toc ['maxdepth' ] = toctree .get ('maxdepth' )
340
340
341
341
for text , entry in toctree .get ('entries' , []):
342
- entry = entry if entry != 'self' else docname
343
- title = text if text else self .titles .get (entry )
344
- subtree = tocs [entry ].next_node (nodes .bullet_list )
342
+ entry_name = entry if entry != 'self' else docname
343
+ title = text if text else self .titles .get (entry_name )
344
+ subtree = tocs [entry_name ].next_node (nodes .bullet_list )
345
345
346
- if subtree :
346
+ if subtree and entry != 'self' :
347
347
if is_subtoc or 'maxdepth' in toc :
348
348
subtree = self ._parse_subtree (subtree , tocs )
349
+ else :
350
+ subtree = None # Sphinx treats "self" as titlesonly
349
351
350
352
toc ['entries' ].append ({
351
- 'entry' : entry ,
353
+ 'entry' : entry_name ,
352
354
'title' : title ,
353
355
'entries' : subtree
354
356
})
@@ -359,8 +361,9 @@ def _parse_subtree(self, tree: nodes.bullet_list, tocs: Dict[str, nodes.bullet_l
359
361
360
362
for child in tree .children :
361
363
if isinstance (child , addnodes .toctree ):
364
+ child_doc = Path (child .source ).relative_to (self .config .src_dir )
362
365
sub_toc = self ._parse_toctree (
363
- docname = Path ( child . source ). stem ,
366
+ docname = child_doc . as_posix (). removesuffix ( child_doc . suffix ) ,
364
367
is_subtoc = True , tocs = tocs ,
365
368
toctree = child ,
366
369
)
0 commit comments