diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-17 13:12:56 +0300 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-05-17 13:12:56 +0300 |
commit | 3c7d35d2a20cfa7c915538704680a33db87c0563 (patch) | |
tree | 5c8e1c9e894f90bf18d77c324ab7829fe0c784a6 /sphinx/transforms | |
parent | 4ad466c7a602ca3b60a9cee15a07f84903a28fe8 (diff) | |
parent | 5f51a1e63f9442439466b7acede87ad21d49bdc0 (diff) |
Merge branch '3.x'
Diffstat (limited to 'sphinx/transforms')
-rw-r--r-- | sphinx/transforms/__init__.py | 17 | ||||
-rw-r--r-- | sphinx/transforms/post_transforms/images.py | 7 |
2 files changed, 16 insertions, 8 deletions
diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py index 1e9abced1..43ea64de8 100644 --- a/sphinx/transforms/__init__.py +++ b/sphinx/transforms/__init__.py @@ -23,6 +23,7 @@ from docutils.utils.smartquotes import smartchars from sphinx import addnodes from sphinx.config import Config 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 @@ -359,12 +360,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): diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py index d1b513b27..f2cacac3c 100644 --- a/sphinx/transforms/post_transforms/images.py +++ b/sphinx/transforms/post_transforms/images.py @@ -10,7 +10,6 @@ import os import re -from hashlib import sha1 from math import ceil from typing import Any, Dict, List, Tuple @@ -19,7 +18,7 @@ from docutils import nodes from sphinx.application import Sphinx from sphinx.locale import __ from sphinx.transforms import SphinxTransform -from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch +from sphinx.util import epoch_to_rfc1123, rfc1123_to_epoch, sha1 from sphinx.util import logging, requests from sphinx.util.images import guess_mimetype, get_image_extension, parse_data_uri from sphinx.util.osutil import ensuredir, movefile @@ -194,7 +193,9 @@ class ImageConverter(BaseImageConverter): super().__init__(*args, **kwargs) def match(self, node: nodes.image) -> bool: - if self.available is None: + if not self.app.builder.supported_image_types: + return False + elif self.available is None: self.available = self.is_available() if not self.available: |