mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add classes to toctree items that indicate depth.
This commit is contained in:
parent
489a12c032
commit
4c3f2f0d7e
6
CHANGES
6
CHANGES
@ -45,6 +45,12 @@ New features added
|
|||||||
- The JavaScript search now searches for objects before searching in
|
- The JavaScript search now searches for objects before searching in
|
||||||
the full text.
|
the full text.
|
||||||
|
|
||||||
|
- TOC tree entries now have CSS classes that make it possible to
|
||||||
|
style them depending on their depth.
|
||||||
|
|
||||||
|
- Highlighted code blocks now have CSS classes that make it possible
|
||||||
|
to style them depending on their language.
|
||||||
|
|
||||||
- HTML ``<meta>`` tags via the docutils ``meta`` directive are now
|
- HTML ``<meta>`` tags via the docutils ``meta`` directive are now
|
||||||
supported.
|
supported.
|
||||||
|
|
||||||
|
@ -902,9 +902,10 @@ class BuildEnvironment:
|
|||||||
"""Utility: Cut a TOC at a specified depth."""
|
"""Utility: Cut a TOC at a specified depth."""
|
||||||
for subnode in node.children[:]:
|
for subnode in node.children[:]:
|
||||||
if isinstance(subnode, (addnodes.compact_paragraph, nodes.list_item)):
|
if isinstance(subnode, (addnodes.compact_paragraph, nodes.list_item)):
|
||||||
|
subnode['classes'].append('toctree-l%d' % (depth-1))
|
||||||
_walk_depth(subnode, depth, maxdepth, titleoverrides)
|
_walk_depth(subnode, depth, maxdepth, titleoverrides)
|
||||||
elif isinstance(subnode, nodes.bullet_list):
|
elif isinstance(subnode, nodes.bullet_list):
|
||||||
if depth > maxdepth:
|
if maxdepth > 0 and depth > maxdepth:
|
||||||
subnode.parent.replace(subnode, [])
|
subnode.parent.replace(subnode, [])
|
||||||
else:
|
else:
|
||||||
_walk_depth(subnode, depth+1, maxdepth, titleoverrides)
|
_walk_depth(subnode, depth+1, maxdepth, titleoverrides)
|
||||||
@ -958,9 +959,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
|
# prune the tree to maxdepth and replace titles, also set level classes
|
||||||
if maxdepth > 0 and prune:
|
_walk_depth(newnode, 1, prune and maxdepth or 0, titleoverrides)
|
||||||
_walk_depth(newnode, 1, maxdepth, titleoverrides)
|
|
||||||
# replace titles, if needed, and set the target paths in the
|
# replace titles, if needed, and set the target paths in the
|
||||||
# toctrees (they are not known at TOC generation time)
|
# toctrees (they are not known at TOC generation time)
|
||||||
for refnode in newnode.traverse(nodes.reference):
|
for refnode in newnode.traverse(nodes.reference):
|
||||||
|
@ -70,6 +70,8 @@ HTML_XPATH = {
|
|||||||
'contents.html': {
|
'contents.html': {
|
||||||
".//meta[@name='hc'][@content='hcval']": '',
|
".//meta[@name='hc'][@content='hcval']": '',
|
||||||
".//td[@class='label']": '[Ref1]',
|
".//td[@class='label']": '[Ref1]',
|
||||||
|
".//li[@class='toctree-l1']/a": 'Testing various markup',
|
||||||
|
".//li[@class='toctree-l2']/a": 'Admonitions',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user