Merge pull request #10504 from AA-Turner/fix-kbd-findall

Fix `findall` usage in `KeyboardTransform`
This commit is contained in:
Takeshi KOMIYA 2022-06-03 01:20:26 +09:00 committed by GitHub
commit 8aacb338aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 1 deletions

View File

@ -40,7 +40,9 @@ class KeyboardTransform(SphinxPostTransform):
def run(self, **kwargs: Any) -> None: def run(self, **kwargs: Any) -> None:
matcher = NodeMatcher(nodes.literal, classes=["kbd"]) 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()) parts = self.pattern.split(node[-1].astext())
if len(parts) == 1 or self.is_multiwords_key(parts): if len(parts) == 1 or self.is_multiwords_key(parts):
continue continue

View File

@ -0,0 +1,4 @@
Regression test for issue 10495
===============================
:kbd:`spanish - inquisition`

View File

@ -48,3 +48,12 @@ def test_missing_reference_conditional_pending_xref(app, status, warning):
content = (app.outdir / 'index.html').read_text(encoding='utf8') content = (app.outdir / 'index.html').read_text(encoding='utf8')
assert '<span class="n"><span class="pre">Age</span></span>' in content 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')