Fix findall usage in KeyboardTransform

This commit is contained in:
Adam Turner 2022-06-01 00:31:12 +01:00
parent 113e1d8759
commit 04b84e82a0

View File

@ -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() == '':