Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TocTree manipulation on Sphinx 7.2+ #1406

Merged
merged 5 commits into from
Aug 14, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/pydata_sphinx_theme/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Union
from urllib.parse import urlparse

import sphinx
from bs4 import BeautifulSoup
from docutils import nodes
from docutils.nodes import Node
Expand Down Expand Up @@ -63,7 +64,10 @@ def generate_header_nav_html(n_links_before_dropdown: int = 5) -> str:

# Find the active header navigation item so we decide whether to highlight
# Will be empty if there is no active page (root_doc, or genindex etc)
active_header_page = toctree.get_toctree_ancestors(pagename)
if sphinx.version_info[:2] >= (7, 2):
active_header_page = [*_get_toctree_ancestors(app.env.toctree_includes, pagename)]
drammock marked this conversation as resolved.
Show resolved Hide resolved
drammock marked this conversation as resolved.
Show resolved Hide resolved
else:
active_header_page = toctree.get_toctree_ancestors(pagename)
if active_header_page:
# The final list item will be the top-most ancestor
active_header_page = active_header_page[-1]
Expand Down Expand Up @@ -417,7 +421,12 @@ def index_toctree(
kwargs.pop("maxdepth")

toctree = TocTree(app.env)
ancestors = toctree.get_toctree_ancestors(pagename)
if sphinx.version_info[:2] >= (7, 2):
from sphinx.environment.adapters.toctree import _get_toctree_ancestors

ancestors = [*_get_toctree_ancestors(app.env.toctree_includes, pagename)]
else:
ancestors = toctree.get_toctree_ancestors(pagename)
try:
indexname = ancestors[-startdepth]
except IndexError:
Expand Down