summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-11-09 20:43:36 +0100
committerGeorg Brandl <georg@python.org>2008-11-09 20:43:36 +0100
commit9f96010e91fe9f168dc760a348ac0bd3a237b35c (patch)
treec58ab91a897f43287f6e137f0fb635e684d99ef2
parentd0d960d5f8c719b4e8a1694174e7b4d0e147474c (diff)
downloadsphinx-9f96010e91fe9f168dc760a348ac0bd3a237b35c.tar.gz
Add classes to toctree items that indicate depth.
-rw-r--r--CHANGES6
-rw-r--r--sphinx/environment.py8
-rw-r--r--tests/test_build.py2
3 files changed, 12 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index caf3d4d4..05b4d327 100644
--- a/CHANGES
+++ b/CHANGES
@@ -45,6 +45,12 @@ New features added
- The JavaScript search now searches for objects before searching in
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
supported.
diff --git a/sphinx/environment.py b/sphinx/environment.py
index 1ebff842..4cf0e177 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -902,9 +902,10 @@ class BuildEnvironment:
"""Utility: Cut a TOC at a specified depth."""
for subnode in node.children[:]:
if isinstance(subnode, (addnodes.compact_paragraph, nodes.list_item)):
+ subnode['classes'].append('toctree-l%d' % (depth-1))
_walk_depth(subnode, depth, maxdepth, titleoverrides)
elif isinstance(subnode, nodes.bullet_list):
- if depth > maxdepth:
+ if maxdepth > 0 and depth > maxdepth:
subnode.parent.replace(subnode, [])
else:
_walk_depth(subnode, depth+1, maxdepth, titleoverrides)
@@ -958,9 +959,8 @@ class BuildEnvironment:
newnode = addnodes.compact_paragraph('', '', *tocentries)
newnode['toctree'] = True
- # prune the tree to maxdepth and replace titles
- if maxdepth > 0 and prune:
- _walk_depth(newnode, 1, maxdepth, titleoverrides)
+ # prune the tree to maxdepth and replace titles, also set level classes
+ _walk_depth(newnode, 1, prune and maxdepth or 0, titleoverrides)
# replace titles, if needed, and set the target paths in the
# toctrees (they are not known at TOC generation time)
for refnode in newnode.traverse(nodes.reference):
diff --git a/tests/test_build.py b/tests/test_build.py
index c62c2f8c..069d7116 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -70,6 +70,8 @@ HTML_XPATH = {
'contents.html': {
".//meta[@name='hc'][@content='hcval']": '',
".//td[@class='label']": '[Ref1]',
+ ".//li[@class='toctree-l1']/a": 'Testing various markup',
+ ".//li[@class='toctree-l2']/a": 'Admonitions',
},
}