Skip to content

Commit

Permalink
sphinx 6 compat (#1314)
Browse files Browse the repository at this point in the history
  • Loading branch information
drammock committed May 9, 2023
1 parent f15ecfe commit a034b2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/pydata_sphinx_theme/toctree.py
Expand Up @@ -12,6 +12,8 @@
from sphinx.application import Sphinx
from sphinx.environment.adapters.toctree import TocTree

from .utils import traverse_or_findall


def add_inline_math(node: Node) -> str:
"""Render a node with HTML tags that activate MathJax processing.
Expand Down Expand Up @@ -72,9 +74,8 @@ def generate_header_nav_html(n_links_before_dropdown: int = 5) -> str:
# Iterate through each toctree node in the root document
# Grab the toctree pages and find the relative link + title.
links_html = []
# TODO: just use "findall" once docutils min version >=0.18.1
meth = "findall" if hasattr(root, "findall") else "traverse"
for toc in getattr(root, meth)(toctree_node):
# TODO: use `root.findall(toctree_node)` once docutils min version >=0.18.1
for toc in traverse_or_findall(root, toctree_node):
for title, page in toc.attributes["entries"]:
# if the page is using "self" use the correct link
page = toc.attributes["parent"] if page == "self" else page
Expand Down Expand Up @@ -382,9 +383,8 @@ def get_local_toctree_for(
kwargs["maxdepth"] = int(kwargs["maxdepth"])
kwargs["collapse"] = collapse

# FIX: Can just use "findall" once docutils 0.18+ is required
meth = "findall" if hasattr(doctree, "findall") else "traverse"
for toctreenode in getattr(doctree, meth)(addnodes.toctree):
# TODO: use `doctree.findall(addnodes.toctree)` once docutils min version >=0.18.1
for toctreenode in traverse_or_findall(doctree, addnodes.toctree):
toctree = self.resolve(docname, builder, toctreenode, prune=True, **kwargs)
if toctree:
toctrees.append(toctree)
Expand Down
14 changes: 11 additions & 3 deletions src/pydata_sphinx_theme/translator.py
Expand Up @@ -10,6 +10,8 @@
from sphinx.ext.autosummary import autosummary_table
from sphinx.util import logging

from .utils import traverse_or_findall

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -118,16 +120,22 @@ def find_target(search_id, node):
)

# NOTE: Replacing with underscores creates the possibility for
# conflicting references. We should check for these and warn the
# conflicting references. Here we check for these and warn the
# user if any are found.
if any(document.traverse(condition=partial(find_target, sanitized_id))):
if any(
traverse_or_findall(
document, condition=partial(find_target, sanitized_id)
)
):
logger.warning(
f'Sanitized reference "{sanitized_id}" for "{target_id}" '
"conflicts with an existing reference!"
)

# Find nodes with the given ID (there should only be one)
targets = document.traverse(condition=partial(find_target, target_id))
targets = traverse_or_findall(
document, condition=partial(find_target, target_id)
)
# Replace dots with underscores in the target node ID
for target in targets:
# NOTE: By itself, modifying the target `ids` here seems to be
Expand Down

0 comments on commit a034b2f

Please sign in to comment.