mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Bug #1046: templating toctree() does not expand to maxdepth past maxdepth
If the current page is nested larger than maxdepth it gets deleted before it can be marked as current. The toctree then callapses to the top entries. Split _walk_depth in two parts, first just add the current tag, and remove unneeded entries in a second call.
This commit is contained in:
parent
50fadb9e94
commit
567671f4d8
@ -1342,18 +1342,22 @@ class BuildEnvironment:
|
||||
if maxdepth > 0 and depth > maxdepth:
|
||||
subnode.parent.replace(subnode, [])
|
||||
else:
|
||||
# to find out what to collapse, *first* walk subitems,
|
||||
# since that determines which children point to the
|
||||
# current page
|
||||
# recurse on children
|
||||
_walk_depth(subnode, depth+1, maxdepth)
|
||||
# cull sub-entries whose parents aren't 'current'
|
||||
if (collapse and depth > 1 and
|
||||
'iscurrent' not in subnode.parent):
|
||||
subnode.parent.remove(subnode)
|
||||
|
||||
def _mark_current(node):
|
||||
"""Mark current page and its parents with the 'current' class."""
|
||||
for subnode in node.children[:]:
|
||||
if isinstance(subnode, (addnodes.compact_paragraph,
|
||||
nodes.list_item, nodes.bullet_list)):
|
||||
# for <p>, <li> and <ul>, just recurse to children
|
||||
_mark_current(subnode)
|
||||
elif isinstance(subnode, nodes.reference):
|
||||
# for <a>, identify which entries point to the current
|
||||
# document and therefore may not be collapsed
|
||||
# for <a>, identify the current document
|
||||
if subnode['refuri'] == docname:
|
||||
if not subnode['anchorname']:
|
||||
# give the whole branch a 'current' class
|
||||
@ -1472,6 +1476,7 @@ class BuildEnvironment:
|
||||
newnode['toctree'] = True
|
||||
|
||||
# prune the tree to maxdepth and replace titles, also set level classes
|
||||
_mark_current(newnode)
|
||||
_walk_depth(newnode, 1, prune and maxdepth or 0)
|
||||
|
||||
# set the target paths in the toctrees (they are not known at TOC
|
||||
|
Loading…
Reference in New Issue
Block a user