Merge pull request #9565 from JustinTArthur/9564-fix_highlighted_code_role_smartquotes

Check complete ancestry of text nodes for smartquotes eligibility.
This commit is contained in:
Takeshi KOMIYA 2021-08-29 16:56:16 +09:00 committed by GitHub
commit baacc26b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 7 deletions

View File

@ -38,6 +38,8 @@ Bugs fixed
* #9267: html theme: CSS and JS files added by theme were loaded twice
* #9535 comment: C++, fix parsing of defaulted function parameters that are
function pointers.
* #9564: smartquotes: don't adjust typography for text with
language-highlighted ``:code:`` role.
Testing
--------

View File

@ -589,14 +589,16 @@ NON_SMARTQUOTABLE_PARENT_NODES = (
def is_smartquotable(node: Node) -> bool:
"""Check whether the node is smart-quotable or not."""
if isinstance(node.parent, NON_SMARTQUOTABLE_PARENT_NODES):
for pnode in traverse_parent(node.parent):
if isinstance(pnode, NON_SMARTQUOTABLE_PARENT_NODES):
return False
elif pnode.get('support_smartquotes', None) is False:
return False
if getattr(node, 'support_smartquotes', None) is False:
return False
elif node.parent.get('support_smartquotes', None) is False:
return False
elif getattr(node, 'support_smartquotes', None) is False:
return False
else:
return True
return True
def process_only_nodes(document: Node, tags: "Tags") -> None:

View File

@ -2,3 +2,7 @@ test-smartquotes
================
-- "Sphinx" is a tool that makes it easy ...
.. toctree::
literals

View File

@ -0,0 +1,12 @@
literals
========
.. role:: python(code)
:language: python
.. default-role:: python
Standard :code:`code role with 'quotes'`
This is a Python :python:`{'code': 'role', 'with': 'quotes'}`.
This is a ``literal with 'quotes'``

View File

@ -9,6 +9,7 @@
"""
import pytest
from html5lib import HTMLParser
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
@ -19,6 +20,24 @@ def test_basic(app, status, warning):
assert '<p> “Sphinx” is a tool that makes it easy …</p>' in content
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
def test_literals(app, status, warning):
app.build()
with (app.outdir / 'literals.html').open() as html_file:
etree = HTMLParser(namespaceHTMLElements=False).parse(html_file)
for code_element in etree.iter('code'):
code_text = ''.join(code_element.itertext())
if code_text.startswith('code role'):
assert "'quotes'" in code_text
elif code_text.startswith('{'):
assert code_text == "{'code': 'role', 'with': 'quotes'}"
elif code_text.startswith('literal'):
assert code_text == "literal with 'quotes'"
@pytest.mark.sphinx(buildername='text', testroot='smartquotes', freshenv=True)
def test_text_builder(app, status, warning):
app.build()