Commits

Anonymous committed ea62002

Add maxdepth for TOCs.

  • Participants
  • Parent commits b77eee0

Comments (0)

Files changed (4)

 
 * 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
 ----------
 

File doc/changes.rst

+:tocdepth: 2
+
 .. _changes:
 
 Changes in Sphinx

File doc/markup/misc.rst

 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

File sphinx/environment.py

         """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):
                                             *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)
                     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'])