summaryrefslogtreecommitdiff
path: root/sphinx/util/docutils.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2022-01-03 00:57:31 +0900
committerGitHub <noreply@github.com>2022-01-03 00:57:31 +0900
commit08a87d945a8ca7770c589ea878e9b095ed35e6d4 (patch)
tree9ceec80c4117bef6e2f0a960c85d99237475cfe7 /sphinx/util/docutils.py
parenta0919172190ee147d44288a0ac67712870ca965e (diff)
parent05a898ecb4ff8e654a053a1ba5131715a4514812 (diff)
downloadsphinx-git-08a87d945a8ca7770c589ea878e9b095ed35e6d4.tar.gz
Merge pull request #10044 from tk0miya/9777_Node.findall
Migrate to Node.findall() from Node.traverse()
Diffstat (limited to 'sphinx/util/docutils.py')
-rw-r--r--sphinx/util/docutils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py
index 456fa9576..c3a6ff9e2 100644
--- a/sphinx/util/docutils.py
+++ b/sphinx/util/docutils.py
@@ -500,6 +500,16 @@ class SphinxTranslator(nodes.NodeVisitor):
logger.warning(__('unknown node type: %r'), node, location=node)
+# Node.findall() is a new interface to traverse a doctree since docutils-0.18.
+# This applies a patch docutils-0.17 or older to be available Node.findall()
+# method to use it from our codebase.
+if __version_info__ < (0, 18):
+ def findall(self, *args, **kwargs):
+ return iter(self.traverse(*args, **kwargs))
+
+ Node.findall = findall # type: ignore
+
+
# cache a vanilla instance of nodes.document
# Used in new_document() function
__document_cache__: Optional[nodes.document] = None