Skip to content

Commit f432239

Browse files
committed
add compatibility with docutils~=0.18
1 parent 969fe1c commit f432239

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ requires-python = "~=3.7"
2828
dependencies = [
2929
"click>=7.1,<9",
3030
"pyyaml",
31-
"sphinx>=3,<6",
31+
"sphinx>=4,<6",
3232
]
3333

3434
[project.urls]

sphinx_external_toc/_compat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import sys
77
from typing import Any, Callable, Pattern, Type
88

9+
from docutils.nodes import Element
10+
911
if sys.version_info >= (3, 10):
1012
DC_SLOTS: dict = {"slots": True}
1113
else:
@@ -136,3 +138,10 @@ def _validator(inst, attr, value):
136138
member_validator(inst, attr, member)
137139

138140
return _validator
141+
142+
# Docutils compatibility
143+
144+
def findall(node: Element):
145+
# findall replaces traverse in docutils v0.18
146+
# note a difference is that findall is an iterator
147+
return getattr(node, "findall", node.traverse)

sphinx_external_toc/events.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
from sphinx.util.docutils import SphinxDirective
1515
from sphinx.util.matching import Matcher, patfilter, patmatch
1616

17+
1718
from .api import Document, FileItem, GlobItem, SiteMap, UrlItem
19+
from ._compat import findall
1820
from .parsing import parse_toc_yaml
1921

2022
logger = logging.getLogger(__name__)
@@ -164,7 +166,7 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
164166
Adapted from `sphinx/directives/other.py::TocTree`
165167
"""
166168
# check for existing toctrees and raise warning
167-
for node in doctree.traverse(toctree_node):
169+
for node in findall(doctree)(toctree_node):
168170
create_warning(
169171
app,
170172
doctree,
@@ -174,7 +176,7 @@ def insert_toctrees(app: Sphinx, doctree: nodes.document) -> None:
174176
)
175177

176178
toc_placeholders: List[TableOfContentsNode] = list(
177-
doctree.traverse(TableOfContentsNode)
179+
findall(doctree)(TableOfContentsNode)
178180
)
179181

180182
site_map: SiteMap = app.env.external_site_map

0 commit comments

Comments
 (0)