mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Regression: restore extraction of data-URI images from source for builders whose output formats do not support them natively (#12344)
This commit is contained in:
parent
b5b383fd47
commit
778013f91a
@ -73,6 +73,9 @@ Bugs fixed
|
||||
* #12459: Add valid-type arguments to the ``linkcheck_rate_limit_timeout``
|
||||
configuration setting.
|
||||
Patch by James Addison.
|
||||
* #12331: Resolve data-URI-image-extraction regression from v7.3.0 affecting
|
||||
builders without native support for data-URIs in their output format.
|
||||
Patch by James Addison.
|
||||
|
||||
Improvements
|
||||
------------
|
||||
|
@ -71,9 +71,9 @@ class Builder:
|
||||
#: The list of MIME types of image formats supported by the builder.
|
||||
#: Image files are searched in the order in which they appear here.
|
||||
supported_image_types: list[str] = []
|
||||
#: The builder supports remote images or not.
|
||||
#: The builder can produce output documents that may fetch external images when opened.
|
||||
supported_remote_images = False
|
||||
#: The builder supports data URIs or not.
|
||||
#: The file format produced by the builder allows images to be embedded using data-URIs.
|
||||
supported_data_uri_images = False
|
||||
|
||||
def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
|
||||
|
@ -115,10 +115,8 @@ class DataURIExtractor(BaseImageConverter):
|
||||
default_priority = 150
|
||||
|
||||
def match(self, node: nodes.image) -> bool:
|
||||
if not self.app.builder.supported_remote_images:
|
||||
return False
|
||||
if self.app.builder.supported_data_uri_images is True:
|
||||
return False
|
||||
return False # do not transform the image; data URIs are valid in the build output
|
||||
return node['uri'].startswith('data:')
|
||||
|
||||
def handle(self, node: nodes.image) -> None:
|
||||
|
@ -27,3 +27,8 @@ test-image
|
||||
|
||||
.. non-exist remote image
|
||||
.. image:: http://localhost:7777/NOT_EXIST.PNG
|
||||
|
||||
.. a self-contained image within a data URI
|
||||
This image was generated using ImageMagick 6.9 with the command ``convert -pointsize 32 -font Noto-Sans-Egyptian-Hieroglyphs-Regular caption:$(printf '\U13080') -trim -border 2 -monochrome eoh.png``
|
||||
.. image:: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAjAQAAAADKt6U+AAAAAmJLR0QAAd2KE6QAAAAHdElNRQfoBQIVBgOBlOMTAAAAEGNhTnYAAAAtAAAAOwAAAAEAAAATst46RgAAAJtJREFUCNdNz70KwkAMAOA8iOhjuGh9HB9BCtoTHHwMH0Mc7KWTmx0dHDpovUk6HCil3sUmATHLR/4IAeJA+LEWPmbEeHJMWbTMZDA0CNFn8x1COFPaIHQ55R7hlZGdIjwj2aovRjJbhPvMLNN+r0g2vB7ByIWbHqqVh3LR3lhZWM0qYV8qjU6+lc4J7ZVx4SjEINBKOSinv/+YL1xvsJE6ztdqAAAADHRFWHRjYXB0aW9uAPCTgoD4hdKUAAAAD3RFWHRjYXB0aW9uOmxpbmVzADGoBz2RAAAAAElFTkSuQmCC
|
||||
:alt: The Eye of Horus in a black font on a white background.
|
||||
|
@ -409,6 +409,7 @@ def test_copy_images(app, status, warning):
|
||||
images = {image.name for image in images_dir.rglob('*')}
|
||||
images.discard('python-logo.png')
|
||||
assert images == {
|
||||
# 'ba30773957c3fe046897111afd65a80b81cad089.png', # epub: image from data:image/png URI in source
|
||||
'img.png',
|
||||
'rimg.png',
|
||||
'rimg1.png',
|
||||
|
@ -72,6 +72,7 @@ def test_copy_images(app, status, warning):
|
||||
images_dir = Path(app.outdir) / '_images'
|
||||
images = {image.name for image in images_dir.rglob('*')}
|
||||
assert images == {
|
||||
# 'ba30773957c3fe046897111afd65a80b81cad089.png', # html: image from data:image/png URI in source
|
||||
'img.png',
|
||||
'rimg.png',
|
||||
'rimg1.png',
|
||||
|
@ -1711,6 +1711,7 @@ def test_copy_images(app, status, warning):
|
||||
}
|
||||
images.discard('sphinx.png')
|
||||
assert images == {
|
||||
'ba30773957c3fe046897111afd65a80b81cad089.png', # latex: image from data:image/png URI in source
|
||||
'img.pdf',
|
||||
'rimg.png',
|
||||
'testimäge.png',
|
||||
|
@ -124,6 +124,7 @@ def test_copy_images(app, status, warning):
|
||||
images = {image.name for image in images_dir.rglob('*')}
|
||||
images.discard('python-logo.png')
|
||||
assert images == {
|
||||
'ba30773957c3fe046897111afd65a80b81cad089.png', # texinfo: image from data:image/png URI in source
|
||||
'img.png',
|
||||
'rimg.png',
|
||||
'testimäge.png',
|
||||
|
Loading…
Reference in New Issue
Block a user