Fix #9103: LaTeX: imgconverter: conversion runs even if not needed

The imgconverter unexpectedly goes to convert even if the given image
is supported by the target builder when the image globbing is not used.
This enables format guess-ing on not globbed.
This commit is contained in:
Takeshi KOMIYA 2021-04-17 16:51:19 +09:00
parent 8954770f67
commit 5f56d4146e
5 changed files with 8 additions and 1 deletions

View File

@ -16,6 +16,7 @@ Deprecated
Features added Features added
-------------- --------------
* #9103: LaTeX: imgconverter: conversion runs even if not needed
* #9023: More CSS classes on domain descriptions, see :ref:`nodes` for details. * #9023: More CSS classes on domain descriptions, see :ref:`nodes` for details.
Bugs fixed Bugs fixed

View File

@ -197,7 +197,7 @@ class ImageConverter(BaseImageConverter):
def match(self, node: nodes.image) -> bool: def match(self, node: nodes.image) -> bool:
if not self.app.builder.supported_image_types: if not self.app.builder.supported_image_types:
return False return False
elif set(node['candidates']) & set(self.app.builder.supported_image_types): elif set(self.guess_mimetypes(node)) & set(self.app.builder.supported_image_types):
# builder supports the image; no need to convert # builder supports the image; no need to convert
return False return False
elif self.available is None: elif self.available is None:

Binary file not shown.

View File

@ -2,3 +2,4 @@ test-ext-imgconverter
===================== =====================
.. image:: svgimg.svg .. image:: svgimg.svg
.. image:: img.pdf

View File

@ -19,6 +19,11 @@ def test_ext_imgconverter(app, status, warning):
app.builder.build_all() app.builder.build_all()
content = (app.outdir / 'python.tex').read_text() content = (app.outdir / 'python.tex').read_text()
# supported image (not converted)
assert '\\sphinxincludegraphics{{img}.pdf}' in content
# non supported image (converted)
assert '\\sphinxincludegraphics{{svgimg}.png}' in content assert '\\sphinxincludegraphics{{svgimg}.png}' in content
assert not (app.outdir / 'svgimg.svg').exists() assert not (app.outdir / 'svgimg.svg').exists()
assert (app.outdir / 'svgimg.png').exists() assert (app.outdir / 'svgimg.png').exists()