13
13
from docutils .parsers .rst .directives .admonitions import BaseAdmonition
14
14
from docutils .parsers .rst .directives .misc import Class
15
15
from docutils .parsers .rst .directives .misc import Include as BaseInclude
16
+ from docutils .statemachine import ViewList
16
17
17
18
from sphinx import addnodes
18
19
from sphinx .locale import versionlabels , _
@@ -57,8 +58,14 @@ def run(self):
57
58
self .options .setdefault ('name' , nodes .fully_normalize_name (caption ))
58
59
59
60
ret = []
61
+ # Children of the internal toctree node; these will be rewritten by
62
+ # traversals (and so having other references into these will also
63
+ # get rewritten) but, nicely, are not rendered directly due to the
64
+ # way that the environment code deals with toctrees.
65
+ others = []
60
66
# (title, ref) pairs, where ref may be a document, or an external link,
61
- # and title may be None if the document's title is to be used
67
+ # or a node. title may be None if the document's title is to be used
68
+ # and must be None if a node is given as a ref.
62
69
entries = []
63
70
includefiles = []
64
71
all_docnames = env .found_docs .copy ()
@@ -67,7 +74,12 @@ def run(self):
67
74
for entry in self .content :
68
75
if not entry :
69
76
continue
70
- if glob and ('*' in entry or '?' in entry or '[' in entry ):
77
+ if entry .startswith ("_ " ):
78
+ node = nodes .paragraph ()
79
+ self .state .nested_parse (ViewList ([entry [2 :]]), 0 , node )
80
+ others .append (node )
81
+ entries .append ((None , node ))
82
+ elif glob and ('*' in entry or '?' in entry or '[' in entry ):
71
83
patname = docname_join (env .docname , entry )
72
84
docnames = sorted (patfilter (all_docnames , patname ))
73
85
for docname in docnames :
@@ -119,6 +131,7 @@ def run(self):
119
131
subnode ['includehidden' ] = 'includehidden' in self .options
120
132
subnode ['numbered' ] = self .options .get ('numbered' , 0 )
121
133
subnode ['titlesonly' ] = 'titlesonly' in self .options
134
+ subnode .children = others
122
135
set_source_info (self , subnode )
123
136
wrappernode = nodes .compound (classes = ['toctree-wrapper' ])
124
137
wrappernode .append (subnode )
0 commit comments