Allow "self" in toctrees, as a reference to the document containing the directive.

This commit is contained in:
Georg Brandl 2009-02-17 18:17:17 +01:00
parent fd1313e7b8
commit 38e766c231
2 changed files with 15 additions and 1 deletions

View File

@ -53,7 +53,7 @@ def toctree_directive(name, arguments, options, content, lineno,
docname = docname[:-len(suffix)]
# absolutize filenames
docname = docname_join(env.docname, docname)
if url_re.match(ref):
if url_re.match(ref) or ref == 'self':
entries.append((title, ref))
elif docname not in env.found_docs:
ret.append(state.document.reporter.warning(
@ -74,6 +74,7 @@ def toctree_directive(name, arguments, options, content, lineno,
'toctree glob pattern %r didn\'t match any documents'
% entry, line=lineno))
subnode = addnodes.toctree()
subnode['parent'] = env.docname
subnode['entries'] = entries
subnode['includefiles'] = includefiles
subnode['maxdepth'] = options.get('maxdepth', -1)

View File

@ -1013,6 +1013,19 @@ class BuildEnvironment:
para = addnodes.compact_paragraph('', '', reference)
item = nodes.list_item('', para)
toc = nodes.bullet_list('', item)
elif ref == 'self':
# 'self' refers to the document from which this toctree originates.
ref = toctreenode['parent']
if not title:
title = self.titles[ref].astext()
reference = nodes.reference('', '',
refuri=ref,
anchorname='',
*[nodes.Text(title)])
para = addnodes.compact_paragraph('', '', reference)
item = nodes.list_item('', para)
# Don't show subitems.
toc = nodes.bullet_list('', item)
else:
toc = self.tocs[ref].deepcopy()
if title and toc.children and len(toc.children) == 1: