summaryrefslogtreecommitdiffstats
path: root/debian/patches/data_uris.diff
blob: 37dd50a0add05cfbbe7adc49b9775be9ffd24e56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
From: James Addison <55152140+jayaddison@users.noreply.github.com>
Date: Wed, 3 Jul 2024 02:16:43 +0100
Subject: Regression: restore extraction of data-URI images from source for
 builders whose output formats do not support them natively (#12344)

(cherry picked from commit 778013f91a650f585bd7bf346d781d5bd9392e46)
---
 sphinx/transforms/post_transforms/images.py | 4 +---
 tests/roots/test-images/index.rst           | 5 +++++
 tests/test_builders/test_build_latex.py     | 1 +
 tests/test_builders/test_build_texinfo.py   | 1 +
 4 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py
index 18ad51d..9a6e1be 100644
--- a/sphinx/transforms/post_transforms/images.py
+++ b/sphinx/transforms/post_transforms/images.py
@@ -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:
diff --git a/tests/roots/test-images/index.rst b/tests/roots/test-images/index.rst
index 9b9aac1..f6d7160 100644
--- a/tests/roots/test-images/index.rst
+++ b/tests/roots/test-images/index.rst
@@ -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.
diff --git a/tests/test_builders/test_build_latex.py b/tests/test_builders/test_build_latex.py
index 0776c74..ba8fc62 100644
--- a/tests/test_builders/test_build_latex.py
+++ b/tests/test_builders/test_build_latex.py
@@ -1710,6 +1710,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',
diff --git a/tests/test_builders/test_build_texinfo.py b/tests/test_builders/test_build_texinfo.py
index f9effb2..3b8e276 100644
--- a/tests/test_builders/test_build_texinfo.py
+++ b/tests/test_builders/test_build_texinfo.py
@@ -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',