@@ -41,6 +41,7 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
4141 toctree = TocTree (app .env ).get_toctree_for (
4242 pagename , app .builder , collapse = collapse , maxdepth = maxdepth , ** kwargs
4343 )
44+
4445 # If no toctree is defined (AKA a single-page site), skip this
4546 if toctree is None :
4647 return []
@@ -51,8 +52,14 @@ def get_nav_object(maxdepth=None, collapse=True, **kwargs):
5152 # <list_item classes="toctree-l1">
5253 # <list_item classes="toctree-l1">
5354 # `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 )
5663
5764 # Now convert our docutils nodes into dicts that Jinja can use
5865 nav = [docutils_node_to_jinja (child , only_pages = True )
@@ -91,6 +98,12 @@ def docutils_node_to_jinja(list_item, only_pages=False):
9198 The TocTree, converted into a dictionary with key/values that work
9299 within Jinja.
93100 """
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
94107 if not list_item .children :
95108 return None
96109
@@ -112,6 +125,7 @@ def docutils_node_to_jinja(list_item, only_pages=False):
112125 nav ["title" ] = title
113126 nav ["url" ] = url
114127 nav ["active" ] = active
128+ nav ["type" ] = "ref"
115129
116130 # Recursively convert children as well
117131 # If there are sub-pages for this list_item, there should be two children:
0 commit comments