Skip to content

Commit 58a9d8f

Browse files
choldgrafjorisvandenbossche
authored andcommitted
Fix parsing of multiple toctree directives on a single page / with a caption (pandas-dev#50)
1 parent c8b8501 commit 58a9d8f

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

pandas-docs/source/index.rst.template

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ See the :ref:`overview` for more detail about what's in the library.
5353
whatsnew/index
5454
{% endif -%}
5555

56+
.. toctree::
57+
:maxdepth: 2
58+
:caption: An extra caption. This item should be at the end of page nav (and duplicated)
59+
60+
development/index
61+
5662

5763
* :doc:`whatsnew/v0.25.0`
5864
* :doc:`install`

pandas_sphinx_theme/__init__.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sphinx.builders.html
99

1010
from .bootstrap_html_translator import BootstrapHTML5Translator
11-
11+
import docutils
1212

1313
__version__ = "0.0.1.dev0"
1414

@@ -27,7 +27,7 @@ def convert_docutils_node(list_item, only_pages=False):
2727

2828
if only_pages and '#' in url:
2929
return None
30-
30+
3131
nav = {}
3232
nav["title"] = title
3333
nav["url"] = url
@@ -47,18 +47,24 @@ def update_page_context(self, pagename, templatename, ctx, event_arg):
4747
from sphinx.environment.adapters.toctree import TocTree
4848

4949
def get_nav_object(**kwds):
50+
"""Return a list of nav links that can be accessed from Jinja."""
5051
toctree = TocTree(self.env).get_toctree_for(
5152
pagename, self, collapse=True, **kwds
5253
)
5354

55+
# Grab all TOC links from any toctrees on the page
56+
toc_items = [item for child in toctree.children for item in child
57+
if isinstance(item, docutils.nodes.list_item)]
58+
5459
nav = []
55-
for child in toctree.children[0].children:
60+
for child in toc_items:
5661
child_nav = convert_docutils_node(child, only_pages=True)
5762
nav.append(child_nav)
5863

5964
return nav
6065

6166
def get_page_toc_object():
67+
"""Return a list of within-page TOC links that can be accessed from Jinja."""
6268
self_toc = TocTree(self.env).get_toc_for(pagename, self)
6369

6470
try:

0 commit comments

Comments
 (0)