Don't swallow toc entries when resolving subtrees.

This commit is contained in:
Georg Brandl 2008-04-06 16:47:28 +00:00
parent 9fb011bd2a
commit b016896c1c
3 changed files with 21 additions and 10 deletions

View File

@ -5,9 +5,14 @@ Changes in trunk
It works like ``add_description_unit`` but the directive will only It works like ``add_description_unit`` but the directive will only
create a target and no output. create a target and no output.
* sphinx.environment: Don't swallow TOC entries when resolving subtrees.
* sphinx.directives: Allow giving a different title to documents * sphinx.directives: Allow giving a different title to documents
in the toctree. in the toctree.
* sphinx.builder, sphinx.environment: Gracefully handle some exception
cases.
Release 0.1.61950 (Mar 26, 2008) Release 0.1.61950 (Mar 26, 2008)
================================ ================================

View File

@ -7,7 +7,7 @@ Sphinx documentation contents
:maxdepth: 2 :maxdepth: 2
intro intro
Konzepte <concepts> concepts
rest rest
markup/index markup/index
builders builders

View File

@ -703,7 +703,7 @@ class BuildEnvironment:
self.resolve_references(doctree, docname, builder) self.resolve_references(doctree, docname, builder)
# now, resolve all toctree nodes # now, resolve all toctree nodes
def _entries_from_toctree(toctreenode): def _entries_from_toctree(toctreenode, separate=False):
"""Return TOC entries for a toctree node.""" """Return TOC entries for a toctree node."""
includefiles = map(str, toctreenode['includefiles']) includefiles = map(str, toctreenode['includefiles'])
@ -716,13 +716,18 @@ class BuildEnvironment:
self.warn(docname, 'toctree contains ref to nonexisting ' self.warn(docname, 'toctree contains ref to nonexisting '
'file %r' % includefile) 'file %r' % includefile)
else: else:
# resolve all sub-toctrees
for toctreenode in toc.traverse(addnodes.toctree): for toctreenode in toc.traverse(addnodes.toctree):
toctreenode.parent.replace_self( i = toctreenode.parent.index(toctreenode) + 1
_entries_from_toctree(toctreenode)) for item in _entries_from_toctree(toctreenode):
entries.append(toc) toctreenode.parent.insert(i, item)
if entries: i += 1
return addnodes.compact_paragraph('', '', *entries) toctreenode.parent.remove(toctreenode)
return [] if separate:
entries.append(toc)
else:
entries.extend(toc.children)
return entries
def _walk_depth(node, depth, maxdepth, titleoverrides): def _walk_depth(node, depth, maxdepth, titleoverrides):
"""Utility: Cut a TOC at a specified depth.""" """Utility: Cut a TOC at a specified depth."""
@ -738,8 +743,9 @@ class BuildEnvironment:
for toctreenode in doctree.traverse(addnodes.toctree): for toctreenode in doctree.traverse(addnodes.toctree):
maxdepth = toctreenode.get('maxdepth', -1) maxdepth = toctreenode.get('maxdepth', -1)
titleoverrides = toctreenode.get('includetitles', {}) titleoverrides = toctreenode.get('includetitles', {})
newnode = _entries_from_toctree(toctreenode) tocentries = _entries_from_toctree(toctreenode, separate=True)
if newnode is not None: if tocentries:
newnode = addnodes.compact_paragraph('', '', *tocentries)
# prune the tree to maxdepth and replace titles # prune the tree to maxdepth and replace titles
if maxdepth > 0: if maxdepth > 0:
_walk_depth(newnode, 1, maxdepth, titleoverrides) _walk_depth(newnode, 1, maxdepth, titleoverrides)