Anonymous avatar Anonymous committed c7f9d0b

Move adding 'toctree-l%d' classes to _mark_current; this fixes the test suite

Also adjust comments and docstrings to reflect the current state.

Comments (0)

Files changed (1)

sphinx/environment.py

             for subnode in node.children[:]:
                 if isinstance(subnode, (addnodes.compact_paragraph,
                                         nodes.list_item)):
-                    # for <p> and <li>, just indicate the depth level and
-                    # recurse to children
-                    subnode['classes'].append('toctree-l%d' % (depth-1))
+                    # for <p> and <li>, just recurse
                     _walk_depth(subnode, depth, maxdepth)
                 elif isinstance(subnode, nodes.bullet_list):
                     # for <ul>, determine if the depth is too large or if the
                     if maxdepth > 0 and depth > maxdepth:
                         subnode.parent.replace(subnode, [])
                     else:
-                        # recurse on children
+                        # recurse on children, current page is already marked
                         _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."""
+        def _mark_current(node, depth):
+            """Add 'toctree-l%d' and 'current' classes to the toctree."""
             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)
+                                        nodes.list_item)):
+                    # for <p> and <li>, indicate the depth level and recurse
+                    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):
-                    # 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 not subnode['anchorname']:
                             # give the whole branch a 'current' class
         newnode = addnodes.compact_paragraph('', '', *tocentries)
         newnode['toctree'] = True
 
-        # prune the tree to maxdepth and replace titles, also set level classes
-        _mark_current(newnode)
+        # prune the tree to maxdepth, also set toc depth and current classes
+        _mark_current(newnode, 1)
         _walk_depth(newnode, 1, prune and maxdepth or 0)
 
         # set the target paths in the toctrees (they are not known at TOC
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.