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

base64 data image uris are being copied and converted to local embed paths #4402

Closed
justinfx opened this issue Jan 9, 2018 · 3 comments
Closed
Milestone

Comments

@justinfx
Copy link

justinfx commented Jan 9, 2018

Subject: Images using base64 encoded data uris are being converted to local embed paths

Problem

When upgrading from sphinx 1.4.4 to 1.6.5 I have found a change in behaviour for image nodes that are using base64 encoded svgs, as data uris. Where previously they had preserved the data uri value, they are now being copied to the doctree images/embeded/.svg location. This breaks my existing logic because the absolute path is now local, and the images no longer work when the generated content is posted to a server.

I am not sure if this is related to the changes in #3589 and #3860. But that looks like it could be.

How to I ensure that my data uri is left unmodified so that it can be embedded in the generated content and not loaded from the filesystem?

Procedure to reproduce the problem

Use a custom directive or build the docutil nodes manually, and use a data uri for an image node:

icon = nodes.image( uri='data:image/svg+xml; ...' )

Error logs / results

The node is later transformed to:

print icon['uri']
# /path/to/project/root/build/doc/md/doctrees/images/embeded/36368b09e55adde9b6ed443770944b3b62c593d4.svg

Expected results

I would expect to keep the data uri unmodified so that it can be directly embedded instead of loaded from the filesystem.

print icon['uri']
# data:image/svg+xml; ...

Environment info

  • OS: Linux (Ubuntu 16.04)
  • Python version: 2.7.6
  • Sphinx version: 1.6.5
@justinfx
Copy link
Author

justinfx commented Jan 9, 2018

It appears that sphinx.builders.Builder.supported_data_uri_images is a new magic undocumented property that fixes my issue if I set it to True on my custom builder class:

class Builder(builders.Builder):
    supported_data_uri_images = True

Is this the expected usage, if I am creating a markdown builder and I want to be able to support data uri images?

@tk0miya
Copy link
Member

tk0miya commented Jan 9, 2018

Yes, the image translation feature follows supported_data_uri_images.

Surely, we need to update docs for the attributes.

@tk0miya tk0miya added this to the 1.7 milestone Jan 28, 2018
tk0miya added a commit that referenced this issue Jan 29, 2018
docs: Add description for attributes of Builder (refs: #4402)
@tk0miya
Copy link
Member

tk0miya commented Jan 29, 2018

Updated by #4517
Thank you for reporting!

@tk0miya tk0miya closed this as completed Jan 29, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants