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

src attribute overwritten, making iframe ineffective #2255

Closed
5 tasks done
ijlyttle opened this issue Dec 4, 2021 · 7 comments
Closed
5 tasks done

src attribute overwritten, making iframe ineffective #2255

ijlyttle opened this issue Dec 4, 2021 · 7 comments
Labels
question general questions - not an issue

Comments

@ijlyttle
Copy link
Contributor

ijlyttle commented Dec 4, 2021

There is a problem with vembedr which I (think I) have traced back to here. This was first raised by @jnolis, in a tweet.

Here's my example Rmd:

---
title: "src gets rewritten"
output: html_document
---

```{r setup, include=FALSE}
library("htmltools")
```

```{r problem}
tags$iframe(src = "https://www.youtube.com/embed/uV4UpCq2azs")
```

In the past, the <iframe src> attribute would be written verbatim to the HTML file.

Currently, something happens to it, and it doesn't work:

image

My suspicion is that the change happened in #2151 (of course, I could be wrong).

I don't know enough about html-dependencies to be effective to diagnose further, but I stand ready to help.

Thanks!

R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6.1, RStudio 2021.9.1.372

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  base64enc_0.1.3  bslib_0.3.1      digest_0.6.29    evaluate_0.14    fastmap_1.1.0    fs_1.5.1         glue_1.5.1       graphics_4.1.2  
  grDevices_4.1.2  highr_0.9        htmltools_0.5.2  jquerylib_0.1.4  jsonlite_1.7.2   knitr_1.36       magrittr_2.0.1   methods_4.1.2   
  R6_2.5.1         rappdirs_0.3.3   rlang_0.4.12     rmarkdown_2.11.3 sass_0.4.0       stats_4.1.2      stringi_1.7.6    stringr_1.4.0   
  tinytex_0.35     tools_4.1.2      utils_4.1.2      xfun_0.28        yaml_2.2.1      

Pandoc version: 2.14.0.3

Checklist

When filing a bug report, please check the boxes below to confirm that you have provided us with the information we need. Have you:

  • formatted your issue so it is easier for us to read?

  • included a minimal, self-contained, and reproducible example?

  • pasted the output from xfun::session_info('rmarkdown') in your issue?

  • upgraded all your packages to their latest versions (including your versions of R, the RStudio IDE, and relevant R packages)?

  • installed and tested your bug with the development version of the rmarkdown package using remotes::install_github("rstudio/rmarkdown")?

@jnolis
Copy link

jnolis commented Dec 5, 2021

As an additional datapoint, you don't even need the vembedr package to have issues with embedding YouTube. If you use the HTML code directly from YouTube in an RMarkdown file, it won't correctly show when you knit it. Try this example RMarkdown file, with an embeded YouTube video taken from right clicking on a video in YouTube and getting the embed code:

---
title: "test-youtube"
output: html_document
---

<iframe width="1280" height="720" src="https://www.youtube.com/embed/RndK5em1dHo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

After you turn it into HTML, the iframe has the same issue as mentioned above. Not being able to have YouTube videos embedded in RMarkdown files seems like meaningful issue to me, as you might want to use videos as part of tutorials or lessons.

@atusy
Copy link
Collaborator

atusy commented Dec 5, 2021

This behavior comes from html_document(self_contained = TRUE), which tries to include as much external sources as possible into a single html file.

You have two choices to workaround.

  1. use self_contained = FALSE
  2. use data-external = 1 attribute in html tags to let them be exceptions.
    tags$iframe(src = "https://www.youtube.com/embed/uV4UpCq2azs", `data-external` = 1)

@atusy
Copy link
Collaborator

atusy commented Dec 5, 2021

Note that this is the feature of pandoc and is not a bug.

@cderv
Copy link
Collaborator

cderv commented Dec 6, 2021

Thanks @atusy for the quick help and answer !

This is indeed something that comes from Pandoc since 2.11.2 I believe. Pandoc will now encode a wider range of component. You need to use data-external attributes explicitly on elements you don't want Pandoc to encode in a self-contained mode.

To simplify that, note that since knitr 1.34 knitr::include_url() adds the attributes data-external="1" to iframe so that one don't need to remember it or do it explicitly. If you write HTML code directly in R Markdown document, you need to add it yourself.

for vembedr, maybe knitr function could be used maybe to benefit from knit_print and sewing method in knitr.

If you're ok with it, maybe we could close this issue ?

@cderv cderv added the question general questions - not an issue label Dec 6, 2021
@ijlyttle
Copy link
Contributor Author

ijlyttle commented Dec 6, 2021

Thanks @cderv and @autsy!

Happy to close the issue, but may come back to ask for some clarifications, if needed.

@ijlyttle ijlyttle closed this as completed Dec 6, 2021
@cderv
Copy link
Collaborator

cderv commented Dec 6, 2021

Happy to close the issue, but may come back to ask for some clarifications, if needed.

Please do note hesitate. You can also ping me in any PR / issue in vembedr

@github-actions
Copy link

github-actions bot commented Jun 7, 2022

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question general questions - not an issue
Projects
None yet
Development

No branches or pull requests

4 participants