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

Directly include Base64-encoded images in .qmd #6568

Closed
cscheid opened this issue Aug 21, 2023 Discussed in #6567 · 9 comments · Fixed by #7112
Closed

Directly include Base64-encoded images in .qmd #6568

cscheid opened this issue Aug 21, 2023 Discussed in #6567 · 9 comments · Fixed by #7112
Assignees
Labels
bug Something isn't working html Issues with HTML and related web technology (html/css/scss)
Milestone

Comments

@cscheid
Copy link
Collaborator

cscheid commented Aug 21, 2023

Pandoc is appending .png at the end of data URIs. I thought we had fixed this but apparently it's back.

Discussed in #6567

Originally posted by zeileis August 21, 2023

Description

When I include Base64-encoded images directly in .qmd files, they are not rendered correctly. When I just do

![](data:image/png;base64,i [...snip...] =)

Then a .png suffix is added at the end in the <img =src".."> which does not work.

Additionally, in some contexts I get the file name too long (os error 36) error, similar to #4613.

A minimal example replicating the first issue using quarto 1.3.450 and R package base64enc is:

Output of `image(volcano)` in Base64:
```{r}
#| echo: false
#| results: "asis"
## create PNG file
img <- tempfile(fileext = ".png")
png(img)
image(volcano)
dev.off()

## write as base 64
img64 <- sprintf("![](%s)", base64enc::dataURI(file = img, mime = "image/png"))
writeLines(img64)
```

I wasn't able to pinpoint exactly when I get the file name too long error. I only get it with Opengraph/Twitter enabled in _quarto.yml but only in my actual website and not in a minimal fresh website. I can try to dig deeper in case this is needed.

@cscheid cscheid added the html Issues with HTML and related web technology (html/css/scss) label Aug 21, 2023
@cscheid cscheid added this to the v1.4 milestone Aug 21, 2023
@cscheid cscheid self-assigned this Aug 21, 2023
@mcanouil mcanouil added the bug Something isn't working label Aug 21, 2023
@cscheid
Copy link
Collaborator Author

cscheid commented Aug 21, 2023

This is coming from the Pandoc reader, so we can't undo it in Lua.

$ cat pandoc-base64-test.md
![](data:image/png;base64,ithisisabadencoding)

![](data:image/png;base64,ithisisabadencoding.png)
$ quarto pandoc pandoc-base64-test.md --default-image-extension=png -t html
<p><img src="data:image/png;base64,ithisisabadencoding.png" /></p>
<p><img src="data:image/png;base64,ithisisabadencoding.png" /></p>

Possibilities:

  • We can try to work around it in qmd-reader.lua but I would prefer to not touch that file unless absolutely necessary; it's extremely fragile
  • we can try to undo the damage in a Lua filter, but it won't be exact: we might remove intentional .png extensions. I don't know why someone would add a .png extension to a base64-encoded data URI (since that's invalid in base64 encodings) but it makes me uncomfortable to add one more non-invertible transformation to our pipeline.

@zeileis
Copy link

zeileis commented Aug 21, 2023

Thanks for confirming the problem and boiling it down to the --default-image-extension=png option. I had tried pandoc before my report, but not with that option. Should we report this upstream to the pandoc project as well?

@cscheid
Copy link
Collaborator Author

cscheid commented Aug 21, 2023

@zeileis I've already asked @tarleb who is a Pandoc developer. I'll update here when I know more.

@cderv
Copy link
Collaborator

cderv commented Oct 2, 2023

Should we report this upstream to the pandoc project as well?

Did we report this upstream already ? It seems wrong behavior from pandoc 🤔

@cscheid
Copy link
Collaborator Author

cscheid commented Oct 2, 2023

I haven't - go ahead if you want to. I'd rather fix now and remove the need to fix it later.

@cderv
Copy link
Collaborator

cderv commented Oct 2, 2023

I'll do it.
And 100% with you on fixing it right now. Just want to be sure we pass through to their team some behavior that we found.

@zeileis
Copy link

zeileis commented Oct 2, 2023

That's great, thanks!

@cderv
Copy link
Collaborator

cderv commented Oct 3, 2023

FWIW @cscheid this has been solve in current dev version of Pandoc : jgm/pandoc@d62e5f3

Should be available next time we update our Pandoc version bundled.

@cderv
Copy link
Collaborator

cderv commented Oct 30, 2023

This is available in Pandoc 3.1.9 (https://github.com/jgm/pandoc/releases/tag/3.1.9) and will be available in Quarto when this version will be included. Follow up on changelog to know when.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working html Issues with HTML and related web technology (html/css/scss)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants