@@ -41,6 +41,7 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
41
41
toctree = TocTree (app .env ).get_toctree_for (
42
42
pagename , app .builder , collapse = collapse , maxdepth = maxdepth , ** kwargs
43
43
)
44
+
44
45
# If no toctree is defined (AKA a single-page site), skip this
45
46
if toctree is None :
46
47
return []
@@ -51,8 +52,14 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
51
52
# <list_item classes="toctree-l1">
52
53
# <list_item classes="toctree-l1">
53
54
# `list_item`s are the actual TOC links and are the only thing we want
54
- toc_items = [item for child in toctree .children for item in child
55
- if isinstance (item , docutils .nodes .list_item )]
55
+ toc_items = []
56
+ for child in toctree .children :
57
+ if isinstance (child , docutils .nodes .caption ):
58
+ toc_items .append (child )
59
+ elif isinstance (child , docutils .nodes .bullet_list ):
60
+ for list_entries in child :
61
+ if isinstance (list_entries , docutils .nodes .list_item ):
62
+ toc_items .append (list_entries )
56
63
57
64
# Now convert our docutils nodes into dicts that Jinja can use
58
65
nav = [docutils_node_to_jinja (child , only_pages = True )
@@ -91,6 +98,12 @@ def docutils_node_to_jinja(list_item, only_pages=False):
91
98
The TocTree, converted into a dictionary with key/values that work
92
99
within Jinja.
93
100
"""
101
+ # If a caption, pass it through
102
+ if isinstance (list_item , docutils .nodes .caption ):
103
+ nav = {"text" : list_item .astext (), "type" : "caption" }
104
+ return nav
105
+
106
+ # Else, we assume it's a list item and need to parse the item content
94
107
if not list_item .children :
95
108
return None
96
109
@@ -112,6 +125,7 @@ def docutils_node_to_jinja(list_item, only_pages=False):
112
125
nav ["title" ] = title
113
126
nav ["url" ] = url
114
127
nav ["active" ] = active
128
+ nav ["type" ] = "ref"
115
129
116
130
# Recursively convert children as well
117
131
# If there are sub-pages for this list_item, there should be two children:
0 commit comments