Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: restore extraction of data-URI images from source for builders whose output formats do not support them natively. #12344

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jayaddison
Copy link
Contributor

Feature or Bugfix

  • Bugfix

Purpose

  • Restore extraction of images from data: URIs even when the builder has the supported_remote_images flag set to False (the default).

Ambiguity

I think the change could seem counter-intuitive. If I saw this changeset I might ask: if remote images are disabled, then why should we parse and extract an image from a URI on an image node?

The way I've resolved that question while developing it is:

These data-URI images can be considered 'local' to the source -- they're found in the input reStructuredText content, so we don't need to check the builder's supported_remote_images attribute at all during the DataURIExtractor.match method; these are not remote images.

Detail

  • Removes a conditional check that caused a regression when it was fixed to compare against a compatible Python type in 0a76199.

Expected behaviour description

  • When post-transforming source image nodes using the DataURIExtractor:
    • If the builder's file formats supports data: URIs natively, leave the URI reference on the image unmodified, and allow the builder to process it normally.
    • Otherwise, if the URI begins with data:, and the contents are declared as having a supported MIME type, then decode the contents and write them to a hash-based filename with the corresponding filetype extension suffixed.

Relates

@jayaddison jayaddison changed the title Regression: restore the ability of LaTeX builds to include data-URI images. Regression: restore data-URI image extraction for builders that do not support data-URIs in their output. May 2, 2024
@jayaddison jayaddison changed the title Regression: restore data-URI image extraction for builders that do not support data-URIs in their output. Regression: restore INPUT data-URI image extraction for builders that do not support data-URIs in their OUTPUT. May 2, 2024
…` and ``supported_data_uri_images`` builder attributes.
@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep; it's intended as a hint that the same image exists as in the other test_copy_images unit tests, but that it isn't written to file because HTML (and similarly ePub) can natively include img src="data:..." elements.

Probably not required, but if some future change affects the logic, it's possible that all of the relevant test cases would need to be updated, and in that case the cross-reference provided by the comment might be useful.

@jayaddison
Copy link
Contributor Author

I'll remove the shoutiness from the pull request description; that was written at a moment where I'd emerged from confusion about what the supported_data_uri_images flag on a builder means.

@jayaddison jayaddison changed the title Regression: restore INPUT data-URI image extraction for builders that do not support data-URIs in their OUTPUT. Regression: restore extraction of data-URI images from source for builders whose output formats do not support them natively. May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LaTeX/ImageConverter: Regression with data: URIs
2 participants