mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Allow "self" in toctrees, as a reference to the document containing the directive.
This commit is contained in:
parent
fd1313e7b8
commit
38e766c231
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user