mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Move adding 'toctree-l%d' classes to _mark_current; this fixes the test suite
Also adjust comments and docstrings to reflect the current state.
This commit is contained in:
parent
12baf34000
commit
0fe9a0252b
@ -1334,9 +1334,7 @@ class BuildEnvironment:
|
|||||||
for subnode in node.children[:]:
|
for subnode in node.children[:]:
|
||||||
if isinstance(subnode, (addnodes.compact_paragraph,
|
if isinstance(subnode, (addnodes.compact_paragraph,
|
||||||
nodes.list_item)):
|
nodes.list_item)):
|
||||||
# for <p> and <li>, just indicate the depth level and
|
# for <p> and <li>, just recurse
|
||||||
# recurse to children
|
|
||||||
subnode['classes'].append('toctree-l%d' % (depth-1))
|
|
||||||
_walk_depth(subnode, depth, maxdepth)
|
_walk_depth(subnode, depth, maxdepth)
|
||||||
elif isinstance(subnode, nodes.bullet_list):
|
elif isinstance(subnode, nodes.bullet_list):
|
||||||
# for <ul>, determine if the depth is too large or if the
|
# for <ul>, determine if the depth is too large or if the
|
||||||
@ -1344,22 +1342,27 @@ class BuildEnvironment:
|
|||||||
if maxdepth > 0 and depth > maxdepth:
|
if maxdepth > 0 and depth > maxdepth:
|
||||||
subnode.parent.replace(subnode, [])
|
subnode.parent.replace(subnode, [])
|
||||||
else:
|
else:
|
||||||
# recurse on children
|
# recurse on children, current page is already marked
|
||||||
_walk_depth(subnode, depth+1, maxdepth)
|
_walk_depth(subnode, depth+1, maxdepth)
|
||||||
# cull sub-entries whose parents aren't 'current'
|
# cull sub-entries whose parents aren't 'current'
|
||||||
if (collapse and depth > 1 and
|
if (collapse and depth > 1 and
|
||||||
'iscurrent' not in subnode.parent):
|
'iscurrent' not in subnode.parent):
|
||||||
subnode.parent.remove(subnode)
|
subnode.parent.remove(subnode)
|
||||||
|
|
||||||
def _mark_current(node):
|
def _mark_current(node, depth):
|
||||||
"""Mark current page and its parents with the 'current' class."""
|
"""Add 'toctree-l%d' and 'current' classes to the toctree."""
|
||||||
for subnode in node.children[:]:
|
for subnode in node.children[:]:
|
||||||
if isinstance(subnode, (addnodes.compact_paragraph,
|
if isinstance(subnode, (addnodes.compact_paragraph,
|
||||||
nodes.list_item, nodes.bullet_list)):
|
nodes.list_item)):
|
||||||
# for <p>, <li> and <ul>, just recurse to children
|
# for <p> and <li>, indicate the depth level and recurse
|
||||||
_mark_current(subnode)
|
subnode['classes'].append('toctree-l%d' % (depth-1))
|
||||||
|
_mark_current(subnode, depth)
|
||||||
|
elif isinstance(subnode, nodes.bullet_list):
|
||||||
|
# for <ul>, just recurse
|
||||||
|
_mark_current(subnode, depth+1)
|
||||||
elif isinstance(subnode, nodes.reference):
|
elif isinstance(subnode, nodes.reference):
|
||||||
# for <a>, identify the current document
|
# for <a>, identify which entries point to the current
|
||||||
|
# document and therefore may not be collapsed
|
||||||
if subnode['refuri'] == docname:
|
if subnode['refuri'] == docname:
|
||||||
if not subnode['anchorname']:
|
if not subnode['anchorname']:
|
||||||
# give the whole branch a 'current' class
|
# give the whole branch a 'current' class
|
||||||
@ -1477,8 +1480,8 @@ class BuildEnvironment:
|
|||||||
newnode = addnodes.compact_paragraph('', '', *tocentries)
|
newnode = addnodes.compact_paragraph('', '', *tocentries)
|
||||||
newnode['toctree'] = True
|
newnode['toctree'] = True
|
||||||
|
|
||||||
# prune the tree to maxdepth and replace titles, also set level classes
|
# prune the tree to maxdepth, also set toc depth and current classes
|
||||||
_mark_current(newnode)
|
_mark_current(newnode, 1)
|
||||||
_walk_depth(newnode, 1, prune and maxdepth or 0)
|
_walk_depth(newnode, 1, prune and maxdepth or 0)
|
||||||
|
|
||||||
# set the target paths in the toctrees (they are not known at TOC
|
# set the target paths in the toctrees (they are not known at TOC
|
||||||
|
Loading…
Reference in New Issue
Block a user