Skip to content

Commit

Permalink
Merge pull request sphinx-doc#1700 from ericholscher/toctree-name
Browse files Browse the repository at this point in the history
Add initial ability to name a TOC Tree
  • Loading branch information
shimizukawa committed Mar 8, 2015
2 parents f0206f7 + 76c9530 commit c5e0910
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sphinx/directives/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class TocTree(Directive):
final_argument_whitespace = False
option_spec = {
'maxdepth': int,
'name': str,
'glob': directives.flag,
'hidden': directives.flag,
'includehidden': directives.flag,
Expand All @@ -51,6 +52,7 @@ def run(self):
env = self.state.document.settings.env
suffixes = env.config.source_suffix
glob = 'glob' in self.options
name = self.options.get('name')

ret = []
# (title, ref) pairs, where ref may be a document, or an external link,
Expand Down Expand Up @@ -109,6 +111,7 @@ def run(self):
# includefiles only entries that are documents
subnode['includefiles'] = includefiles
subnode['maxdepth'] = self.options.get('maxdepth', -1)
subnode['name'] = name
subnode['glob'] = glob
subnode['hidden'] = 'hidden' in self.options
subnode['includehidden'] = 'includehidden' in self.options
Expand Down
8 changes: 8 additions & 0 deletions sphinx/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,15 @@ def _entries_from_toctree(toctreenode, parents,
separate=False, subtree=False):
"""Return TOC entries for a toctree node."""
refs = [(e[0], e[1]) for e in toctreenode['entries']]
name = toctreenode.attributes.get('name')
entries = []
if name:
entries.extend(
nodes.reference('', '', internal=False,
refuri='', anchorname='',
*[nodes.Text(name)])
)

for (title, ref) in refs:
try:
refdoc = None
Expand Down

0 comments on commit c5e0910

Please sign in to comment.