summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-06-12 21:56:06 +0000
committerGeorg Brandl <georg@python.org>2008-06-12 21:56:06 +0000
commitbd4166c2d656fb237d5f26bd75faddd5e230fbc3 (patch)
tree26a7138aeca34c54347775285e64803c2031c552
parente8bb912a9c088777a90b2adb3e71a9641a24f478 (diff)
downloadsphinx-git-bd4166c2d656fb237d5f26bd75faddd5e230fbc3.tar.gz
Add maxdepth for TOCs.
-rw-r--r--CHANGES3
-rw-r--r--doc/changes.rst2
-rw-r--r--doc/markup/misc.rst7
-rw-r--r--sphinx/environment.py12
4 files changed, 20 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 42e3b77e8..ddc220088 100644
--- a/CHANGES
+++ b/CHANGES
@@ -38,6 +38,9 @@ New features added
* Added TextBuilder to create plain-text output.
+* ``tocdepth`` can be given as a file-wide metadata entry, and specifies
+ the maximum depth of a TOC of this file.
+
Bugs fixed
----------
diff --git a/doc/changes.rst b/doc/changes.rst
index 3d9f758a0..d5927a725 100644
--- a/doc/changes.rst
+++ b/doc/changes.rst
@@ -1,3 +1,5 @@
+:tocdepth: 2
+
.. _changes:
Changes in Sphinx
diff --git a/doc/markup/misc.rst b/doc/markup/misc.rst
index c50621372..98f5485e7 100644
--- a/doc/markup/misc.rst
+++ b/doc/markup/misc.rst
@@ -16,7 +16,12 @@ normal documents can be used to record the author, date of publication and
other metadata. In Sphinx, the docinfo is used as metadata, too, but not
displayed in the output.
-At the moment, only one metadata field is recognized:
+At the moment, these metadata fields are recognized:
+
+``tocdepth``
+ The maximum depth for a table of contents of this file.
+
+ .. versionadded:: 0.4
``nocomments``
If set, the web application won't display a comment form for a page generated
diff --git a/sphinx/environment.py b/sphinx/environment.py
index 608300526..c8996f39d 100644
--- a/sphinx/environment.py
+++ b/sphinx/environment.py
@@ -605,7 +605,12 @@ class BuildEnvironment:
"""Build a TOC from the doctree and store it in the inventory."""
numentries = [0] # nonlocal again...
- def build_toc(node):
+ try:
+ maxdepth = int(self.metadata[docname].get('tocdepth', 0))
+ except ValueError:
+ maxdepth = 0
+
+ def build_toc(node, depth=1):
entries = []
for subnode in node:
if isinstance(subnode, addnodes.toctree):
@@ -636,7 +641,8 @@ class BuildEnvironment:
*nodetext)
para = addnodes.compact_paragraph('', '', reference)
item = nodes.list_item('', para)
- item += build_toc(subnode)
+ if maxdepth == 0 or depth < maxdepth:
+ item += build_toc(subnode, depth+1)
entries.append(item)
if entries:
return nodes.bullet_list('', *entries)
@@ -749,7 +755,7 @@ class BuildEnvironment:
else:
_walk_depth(subnode, depth+1, maxdepth, titleoverrides)
- def _entries_from_toctree(toctreenode, separate=False):
+ def _entries_from_toctree(toctreenode, separate=False):
"""Return TOC entries for a toctree node."""
includefiles = map(str, toctreenode['includefiles'])