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

Support self-contained images in xaringan slides (close #3) #207

Merged
merged 26 commits into from Sep 24, 2020
Merged

Support self-contained images in xaringan slides (close #3) #207

merged 26 commits into from Sep 24, 2020

Conversation

srvanderplas
Copy link
Contributor

@srvanderplas srvanderplas commented Apr 16, 2019

To contribute to this repo, please make sure to:

  • [x ] Sign the CLA http://www.clahub.com/agreements/yihui/xaringan (if you haven't signed it before).
  • [x ] Add a news item to NEWS.md and your name to DESCRIPTION (by alphabetical order) unless you have already been listed there.
  • [x ] Provide a URL to a live example (and even better, a couple of screenshots) if you are contributing a new theme.

Thank you!


Demo: MWE with emoji icon

MWE in xaringan 0.15.1

MWE with self-contained image functionality

diff of HTML files (text file)

Rmd file for MWE

…ding, issue warning if file does not exist
@srvanderplas srvanderplas reopened this Apr 16, 2019
@srvanderplas
Copy link
Contributor Author

Is there anything else I should do for this?

@yihui
Copy link
Owner

yihui commented May 31, 2019

Nope. Sorry I haven't had a chance to review it yet...

Copy link
Collaborator

@pat-s pat-s left a comment

Choose a reason for hiding this comment

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

Hi @srvanderplas! Could you rebase your PR?

Also please format the code in utils.R and test-utils.R to a width of 80.

Could you add an example to your first post showing the changed behavior? That would help a lot.
Afterwards I can have a detailed look at the code :)

@srvanderplas
Copy link
Contributor Author

srvanderplas commented Mar 6, 2020 via email

@mschilli87
Copy link
Contributor

There seem to be quite some unrelated changes in this PR now.

@pat-s
Copy link
Collaborator

pat-s commented Mar 9, 2020

There seem to be quite some unrelated changes in this PR now.

Right, something went wrong during the merge/rebase.

@srvanderplas Could you please clean up and just keep the changes related to this PR? Atm there are many changes to files like NEWS.md or the GH issue template.

@CLAassistant
Copy link

CLAassistant commented Sep 22, 2020

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ yihui
❌ srvanderplas
You have signed the CLA already but the status is still pending? Let us recheck it.

@yihui yihui changed the title Add self-contained images to xaringan Support self-contained images in xaringan slides (close #3) Sep 23, 2020
…o find out images, base64 encode them, store the data in a JSON object, replace the original image URLs with special tokens that contain the original URLs; then in the browser, restore these tokens with the actual base64 data after the slides are rendered

rendering slides should be fast because the Markdown content is still lightweight (contains no base64 data); Markdown content containing base64 data used to be the main bottleneck when rendering self-contained slides, because these huge base54 strings make it really slow for remark.js to render them
Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

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

I've heavily tweaked this PR, and it should be ready to merge now. But I have just submitted a new version of xaringan to CRAN yesterday, so please do not merge this one until that version appears on CRAN (this PR will go to the next version).

Don't tell Jared that he can order his new computer now.

@yihui yihui merged commit 17ff6e2 into yihui:master Sep 24, 2020
yihui added a commit to rstudio/rmarkdown-book that referenced this pull request Sep 24, 2020
@yihui
Copy link
Owner

yihui commented Sep 28, 2020

I'm writing down the basic idea of the implementation here just in case anyone (including my future self) needs to understand it.

Extract and (base64) encode images, and store the encoded data outside the Markdown text as a JS object. After remark.js has rendered the slides, insert the encoded images back to the slides.

1. Markdown images (could be <img/> or background-image: url()

![](foo.png) ![](bar.jpg)

2. Hide them first

![](data:image/png;base64,#foo.png) ![](data:image/png;base64,#bar.jpg)

Put the base64 data outside the Markdown text:

<script>
{
  "foo.png": "data:image/png;base64,*",
  "bar.jpg": "data:image/jpeg;base64,*"
}
</script>

3. Renders slides and post-process them

<textarea>
<img src="data:image/png;base64,#foo.png" /> <img src="data:image/png;base64,#bar.jpg" />
</textarea>

<script>remark.create();</script>
<script>{ base64 data }</script>

4. The src attributes have the correct base64 data now

<img src="data:image/png;base64,*" />
<img src="data:image/jpeg;base64,*" />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants