diff options
author | Adam Turner <9087854+AA-Turner@users.noreply.github.com> | 2022-06-01 00:31:12 +0100 |
---|---|---|
committer | Adam Turner <9087854+AA-Turner@users.noreply.github.com> | 2022-06-01 00:31:12 +0100 |
commit | 04b84e82a019b12d79519082d79e6636238b31a7 (patch) | |
tree | 8a67765a07193104e16c99951d1474ad4bd58b5a /sphinx/builders/html/transforms.py | |
parent | 113e1d8759e444342544bd97ed93bc1622b9a6bb (diff) | |
download | sphinx-git-04b84e82a019b12d79519082d79e6636238b31a7.tar.gz |
Fix `findall` usage in KeyboardTransform
Diffstat (limited to 'sphinx/builders/html/transforms.py')
-rw-r--r-- | sphinx/builders/html/transforms.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/sphinx/builders/html/transforms.py b/sphinx/builders/html/transforms.py index ea596cb4b..7f96c4e60 100644 --- a/sphinx/builders/html/transforms.py +++ b/sphinx/builders/html/transforms.py @@ -40,7 +40,10 @@ class KeyboardTransform(SphinxPostTransform): def run(self, **kwargs: Any) -> None: matcher = NodeMatcher(nodes.literal, classes=["kbd"]) - for node in self.document.findall(matcher): # type: nodes.literal + # this list must be pre-created as during iteration new nodes + # are added which match the condition in the NodeMatcher. + nodes_to_expand = list(self.document.findall(matcher)) + for node in nodes_to_expand: # type: nodes.literal parts = self.pattern.split(node[-1].astext()) if len(parts) == 1 or self.is_multiwords_key(parts): continue @@ -61,6 +64,7 @@ class KeyboardTransform(SphinxPostTransform): node += nodes.Text(sep) except IndexError: pass + _a = 1 def is_multiwords_key(self, parts: List[str]) -> bool: if len(parts) >= 3 and parts[1].strip() == '': |