Skip to content

Commit 778013f

Browse files
authored
Regression: restore extraction of data-URI images from source for builders whose output formats do not support them natively (#12344)
1 parent b5b383f commit 778013f

File tree

8 files changed

+15
-5
lines changed

8 files changed

+15
-5
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Bugs fixed
7373
* #12459: Add valid-type arguments to the ``linkcheck_rate_limit_timeout``
7474
configuration setting.
7575
Patch by James Addison.
76+
* #12331: Resolve data-URI-image-extraction regression from v7.3.0 affecting
77+
builders without native support for data-URIs in their output format.
78+
Patch by James Addison.
7679

7780
Improvements
7881
------------

sphinx/builders/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ class Builder:
7171
#: The list of MIME types of image formats supported by the builder.
7272
#: Image files are searched in the order in which they appear here.
7373
supported_image_types: list[str] = []
74-
#: The builder supports remote images or not.
74+
#: The builder can produce output documents that may fetch external images when opened.
7575
supported_remote_images = False
76-
#: The builder supports data URIs or not.
76+
#: The file format produced by the builder allows images to be embedded using data-URIs.
7777
supported_data_uri_images = False
7878

7979
def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:

sphinx/transforms/post_transforms/images.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,8 @@ class DataURIExtractor(BaseImageConverter):
115115
default_priority = 150
116116

117117
def match(self, node: nodes.image) -> bool:
118-
if not self.app.builder.supported_remote_images:
119-
return False
120118
if self.app.builder.supported_data_uri_images is True:
121-
return False
119+
return False # do not transform the image; data URIs are valid in the build output
122120
return node['uri'].startswith('data:')
123121

124122
def handle(self, node: nodes.image) -> None:

tests/roots/test-images/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ test-image
2727

2828
.. non-exist remote image
2929
.. image:: http://localhost:7777/NOT_EXIST.PNG
30+
31+
.. a self-contained image within a data URI
32+
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``
33+
.. image:: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACoAAAAjAQAAAADKt6U+AAAAAmJLR0QAAd2KE6QAAAAHdElNRQfoBQIVBgOBlOMTAAAAEGNhTnYAAAAtAAAAOwAAAAEAAAATst46RgAAAJtJREFUCNdNz70KwkAMAOA8iOhjuGh9HB9BCtoTHHwMH0Mc7KWTmx0dHDpovUk6HCil3sUmATHLR/4IAeJA+LEWPmbEeHJMWbTMZDA0CNFn8x1COFPaIHQ55R7hlZGdIjwj2aovRjJbhPvMLNN+r0g2vB7ByIWbHqqVh3LR3lhZWM0qYV8qjU6+lc4J7ZVx4SjEINBKOSinv/+YL1xvsJE6ztdqAAAADHRFWHRjYXB0aW9uAPCTgoD4hdKUAAAAD3RFWHRjYXB0aW9uOmxpbmVzADGoBz2RAAAAAElFTkSuQmCC
34+
:alt: The Eye of Horus in a black font on a white background.

tests/test_builders/test_build_epub.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def test_copy_images(app, status, warning):
409409
images = {image.name for image in images_dir.rglob('*')}
410410
images.discard('python-logo.png')
411411
assert images == {
412+
# 'ba30773957c3fe046897111afd65a80b81cad089.png', # epub: image from data:image/png URI in source
412413
'img.png',
413414
'rimg.png',
414415
'rimg1.png',

tests/test_builders/test_build_html_image.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def test_copy_images(app, status, warning):
7272
images_dir = Path(app.outdir) / '_images'
7373
images = {image.name for image in images_dir.rglob('*')}
7474
assert images == {
75+
# 'ba30773957c3fe046897111afd65a80b81cad089.png', # html: image from data:image/png URI in source
7576
'img.png',
7677
'rimg.png',
7778
'rimg1.png',

tests/test_builders/test_build_latex.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ def test_copy_images(app, status, warning):
17111711
}
17121712
images.discard('sphinx.png')
17131713
assert images == {
1714+
'ba30773957c3fe046897111afd65a80b81cad089.png', # latex: image from data:image/png URI in source
17141715
'img.pdf',
17151716
'rimg.png',
17161717
'testimäge.png',

tests/test_builders/test_build_texinfo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ def test_copy_images(app, status, warning):
124124
images = {image.name for image in images_dir.rglob('*')}
125125
images.discard('python-logo.png')
126126
assert images == {
127+
'ba30773957c3fe046897111afd65a80b81cad089.png', # texinfo: image from data:image/png URI in source
127128
'img.png',
128129
'rimg.png',
129130
'testimäge.png',

0 commit comments

Comments
 (0)