diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-01 18:09:55 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-06 18:54:36 +0300 |
commit | 71b653719d2212795545230fe34426c1f78aa993 (patch) | |
tree | 0208845a7a55d79cd50076d47b6b5ee0dccb24ff /sphinx/transforms | |
parent | 6ce265dc813f9ecb92bf1cdf8733fbada7f5c967 (diff) |
Fix #7610: incorrectly renders consecutive backslashes
Diffstat (limited to 'sphinx/transforms')
-rw-r--r-- | sphinx/transforms/__init__.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index a00f04fdf..1605c95b9 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -23,6 +23,7 @@ from sphinx import addnodes from sphinx.config import Config from sphinx.deprecation import RemovedInSphinx40Warning, deprecated_alias from sphinx.locale import _, __ +from sphinx.util import docutils from sphinx.util import logging from sphinx.util.docutils import new_document from sphinx.util.i18n import format_date @@ -360,12 +361,18 @@ class SphinxSmartQuotes(SmartQuotes, SphinxTransform): def get_tokens(self, txtnodes: List[Text]) -> Generator[Tuple[str, str], None, None]: # A generator that yields ``(texttype, nodetext)`` tuples for a list # of "Text" nodes (interface to ``smartquotes.educate_tokens()``). - - texttype = {True: 'literal', # "literal" text is not changed: - False: 'plain'} for txtnode in txtnodes: - notsmartquotable = not is_smartquotable(txtnode) - yield (texttype[notsmartquotable], txtnode.astext()) + if is_smartquotable(txtnode): + if docutils.__version_info__ >= (0, 16): + # SmartQuotes uses backslash escapes instead of null-escapes + text = re.sub(r'(?<=\x00)([-\\\'".`])', r'\\\1', str(txtnode)) + else: + text = txtnode.astext() + + yield ('plain', text) + else: + # skip smart quotes + yield ('literal', txtnode.astext()) class DoctreeReadEvent(SphinxTransform): |