Skip to content

Commit

Permalink
Fix parsing of multiple toctree directives on a single page / with a …
Browse files Browse the repository at this point in the history
…caption (pandas-dev#50)
  • Loading branch information
choldgraf authored and jorisvandenbossche committed Nov 5, 2019
1 parent c8b8501 commit 58a9d8f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions pandas-docs/source/index.rst.template
Expand Up @@ -53,6 +53,12 @@ See the :ref:`overview` for more detail about what's in the library.
whatsnew/index
{% endif -%}

.. toctree::
:maxdepth: 2
:caption: An extra caption. This item should be at the end of page nav (and duplicated)

development/index


* :doc:`whatsnew/v0.25.0`
* :doc:`install`
Expand Down
12 changes: 9 additions & 3 deletions pandas_sphinx_theme/__init__.py
Expand Up @@ -8,7 +8,7 @@
import sphinx.builders.html

from .bootstrap_html_translator import BootstrapHTML5Translator

import docutils

__version__ = "0.0.1.dev0"

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

if only_pages and '#' in url:
return None

nav = {}
nav["title"] = title
nav["url"] = url
Expand All @@ -47,18 +47,24 @@ def update_page_context(self, pagename, templatename, ctx, event_arg):
from sphinx.environment.adapters.toctree import TocTree

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

# Grab all TOC links from any toctrees on the page
toc_items = [item for child in toctree.children for item in child
if isinstance(item, docutils.nodes.list_item)]

nav = []
for child in toctree.children[0].children:
for child in toc_items:
child_nav = convert_docutils_node(child, only_pages=True)
nav.append(child_nav)

return nav

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

try:
Expand Down

0 comments on commit 58a9d8f

Please sign in to comment.