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
Support for "data" URIs in ImageConverter.guess_mimetypes() #10073
Comments
I've created a possible fix: #10074. |
If my understanding is correct, data URIs are extracted to temporary files and detected its mimetype by sphinx/sphinx/transforms/post_transforms/images.py Lines 114 to 144 in 5bf0e3a
Therefore, no additional code is needed to process them, AFAIK. For example, I succeeded to embed SVG image into PDF document using
|
Thanks for looking into this @tk0miya! The In my case it is not used, because the HTML builder can handle
I know that it works for unsupported types (e.g. SVG) in the LaTeX builder. I probably wasn't clear in my description, but the the problem is with supported types (in my case PNG) in the HTML builder. In this case, the converter is supposed to do nothing, but it is called nevertheless, which is wrong. |
I think the expected behavior is that rsvgconverter will not be invoked for the embedded PNG image, right? If so, no reason to "guess mimetypes". How about skipping without guessing? |
Yes.
Don't we have to guess first to be able to check whether the guessed MIME type is supported or not? sphinx/sphinx/transforms/post_transforms/images.py Lines 200 to 202 in 08a87d9
That's what I'm trying to implement in #10074. |
I think all embedded images should be skipped. So it's better to skip them all:
Is any reason to obtain the mime-type from the image? What do you do if the builder does not support the image? |
Yes, thanks, I think you are right! Nobody would use an unsupported MIME type in a "data" URI anyway. I've created an alternative fix based on your suggestion in #10099. |
Is your feature request related to a problem? Please describe.
This problem came up when using the
sphinxcontrib.rsvgconverter
extension, which is supposed to automatically convert SVG images to PDF when using the LaTeX builder, which it does with the help of the external programrsvg-convert
.When using the HTML builder, the extension is supposed to do nothing.
Previously, there was a problem with this (missinglinkelectronics/sphinxcontrib-svg2pdfconverter#8), which was fixed in #8649.
However, there is still one error case remaining:
When using
data
URIs instead of image files, this is still broken.The data type is not recognized in this case and therefore it is handled as unsupported by the builder, even if the builder actually supports it.
Example reST code:
Here is a test repo that shows the problem: https://github.com/mgeier/rsvgconverter-bug.
Describe the solution you'd like
The MIME type of
data
URIs should be checked and correctly recognized so thatsphinxcontrib.rsvgconverter
(and probably other extensions) knows if a supported data type is used.Describe alternatives you've considered
One could just ignore this problem, but then the program
rsvg-convert
has to be installed and it is executed even if it is absolutely not necessary (e.g. for the HTML builder).Additional context
This is where the MIME type is guessed:
sphinx/sphinx/transforms/post_transforms/images.py
Lines 229 to 235 in 08a87d9
The value of
node['candidates']
is{'?': 'data:image/png;base64,...'}
in my case.I'm not sure what the question mark means exactly.
There is already a helper function
parse_data_uri()
, which can probably be used to implement this:sphinx/sphinx/util/images.py
Lines 85 to 103 in 5bf0e3a
The text was updated successfully, but these errors were encountered: