Recognize toctree directives that are not on section toplevel,

but within block items, such as tables.
This commit is contained in:
Georg Brandl 2009-02-14 20:19:01 +01:00
parent a42203a241
commit 33bed1ef6b
2 changed files with 28 additions and 13 deletions

View File

@ -1,6 +1,9 @@
Release 0.5.2 (in development) Release 0.5.2 (in development)
============================== ==============================
* Recognize toctree directives that are not on section toplevel,
but within block items, such as tables.
* Use a new RFC base URL, since rfc.org seems down. * Use a new RFC base URL, since rfc.org seems down.
* Fix a crash in the todolist directive when no todo items are * Fix a crash in the todolist directive when no todo items are

View File

@ -773,20 +773,32 @@ class BuildEnvironment:
except ValueError: except ValueError:
maxdepth = 0 maxdepth = 0
def traverse_in_section(node, cls):
"""Like traverse(), but stay within the same section."""
result = []
if isinstance(node, cls):
result.append(node)
for child in node.children:
if isinstance(child, nodes.section):
continue
result.extend(traverse_in_section(child, cls))
return result
def build_toc(node, depth=1): def build_toc(node, depth=1):
entries = [] entries = []
for subnode in node: for sectionnode in node:
if isinstance(subnode, addnodes.toctree): # find all toctree nodes in this section and add them
# just copy the toctree node which is then resolved # to the toc (just copying the toctree node which is then
# in self.get_and_resolve_doctree # resolved in self.get_and_resolve_doctree)
item = subnode.copy() if not isinstance(sectionnode, nodes.section):
entries.append(item) for toctreenode in traverse_in_section(sectionnode,
# do the inventory stuff addnodes.toctree):
self.note_toctree(docname, subnode) item = toctreenode.copy()
entries.append(item)
# important: do the inventory stuff
self.note_toctree(docname, toctreenode)
continue continue
if not isinstance(subnode, nodes.section): title = sectionnode[0]
continue
title = subnode[0]
# copy the contents of the section title, but without references # copy the contents of the section title, but without references
# and unnecessary stuff # and unnecessary stuff
visitor = SphinxContentsFilter(document) visitor = SphinxContentsFilter(document)
@ -797,7 +809,7 @@ class BuildEnvironment:
# as it is the file's title anyway # as it is the file's title anyway
anchorname = '' anchorname = ''
else: else:
anchorname = '#' + subnode['ids'][0] anchorname = '#' + sectionnode['ids'][0]
numentries[0] += 1 numentries[0] += 1
reference = nodes.reference('', '', refuri=docname, reference = nodes.reference('', '', refuri=docname,
anchorname=anchorname, anchorname=anchorname,
@ -805,7 +817,7 @@ class BuildEnvironment:
para = addnodes.compact_paragraph('', '', reference) para = addnodes.compact_paragraph('', '', reference)
item = nodes.list_item('', para) item = nodes.list_item('', para)
if maxdepth == 0 or depth < maxdepth: if maxdepth == 0 or depth < maxdepth:
item += build_toc(subnode, depth+1) item += build_toc(sectionnode, depth+1)
entries.append(item) entries.append(item)
if entries: if entries:
return nodes.bullet_list('', *entries) return nodes.bullet_list('', *entries)