Skip to content

Commit

Permalink
Merge pull request #10504 from AA-Turner/fix-kbd-findall
Browse files Browse the repository at this point in the history
Fix `findall` usage in `KeyboardTransform`
  • Loading branch information
tk0miya committed Jun 2, 2022
2 parents 28f9ce7 + efdbe06 commit 8aacb33
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sphinx/builders/html/transforms.py
Expand Up @@ -40,7 +40,9 @@ 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.
for node in list(self.document.findall(matcher)): # type: nodes.literal
parts = self.pattern.split(node[-1].astext())
if len(parts) == 1 or self.is_multiwords_key(parts):
continue
Expand Down
Empty file.
@@ -0,0 +1,4 @@
Regression test for issue 10495
===============================

:kbd:`spanish - inquisition`
9 changes: 9 additions & 0 deletions tests/test_transforms_post_transforms.py
Expand Up @@ -48,3 +48,12 @@ def missing_reference(app, env, node, contnode):

content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<span class="n"><span class="pre">Age</span></span>' in content


@pytest.mark.sphinx('html', testroot='transforms-post_transforms-keyboard',
freshenv=True)
def test_keyboard_hyphen_spaces(app):
"""Regression test for issue 10495, we want no crash."""
app.build()
assert "spanish" in (app.outdir / 'index.html').read_text(encoding='utf8')
assert "inquisition" in (app.outdir / 'index.html').read_text(encoding='utf8')

0 comments on commit 8aacb33

Please sign in to comment.