mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
commit
baacc26b29
2
CHANGES
2
CHANGES
@ -38,6 +38,8 @@ Bugs fixed
|
|||||||
* #9267: html theme: CSS and JS files added by theme were loaded twice
|
* #9267: html theme: CSS and JS files added by theme were loaded twice
|
||||||
* #9535 comment: C++, fix parsing of defaulted function parameters that are
|
* #9535 comment: C++, fix parsing of defaulted function parameters that are
|
||||||
function pointers.
|
function pointers.
|
||||||
|
* #9564: smartquotes: don't adjust typography for text with
|
||||||
|
language-highlighted ``:code:`` role.
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -589,13 +589,15 @@ NON_SMARTQUOTABLE_PARENT_NODES = (
|
|||||||
|
|
||||||
def is_smartquotable(node: Node) -> bool:
|
def is_smartquotable(node: Node) -> bool:
|
||||||
"""Check whether the node is smart-quotable or not."""
|
"""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
|
return False
|
||||||
elif node.parent.get('support_smartquotes', None) is False:
|
elif pnode.get('support_smartquotes', None) is False:
|
||||||
return False
|
return False
|
||||||
elif getattr(node, 'support_smartquotes', None) is False:
|
|
||||||
|
if getattr(node, 'support_smartquotes', None) is False:
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,3 +2,7 @@ test-smartquotes
|
|||||||
================
|
================
|
||||||
|
|
||||||
-- "Sphinx" is a tool that makes it easy ...
|
-- "Sphinx" is a tool that makes it easy ...
|
||||||
|
|
||||||
|
.. toctree::
|
||||||
|
|
||||||
|
literals
|
||||||
|
12
tests/roots/test-smartquotes/literals.rst
Normal file
12
tests/roots/test-smartquotes/literals.rst
Normal 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'``
|
@ -9,6 +9,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from html5lib import HTMLParser
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx(buildername='html', testroot='smartquotes', freshenv=True)
|
@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
|
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)
|
@pytest.mark.sphinx(buildername='text', testroot='smartquotes', freshenv=True)
|
||||||
def test_text_builder(app, status, warning):
|
def test_text_builder(app, status, warning):
|
||||||
app.build()
|
app.build()
|
||||||
|
Loading…
Reference in New Issue
Block a user