rmarkdown icon indicating copy to clipboard operation
rmarkdown copied to clipboard

Limitations with htmltools metadata

Open jcheng5 opened this issue 5 years ago • 4 comments

I'm happy to help fix these, just putting here so they're captured.

htmlDependencies with src=c(href="...") isn't supported

---
output: html_document
---

```{r echo=FALSE}
library(htmltools)
```
```{r}
tagList(htmlDependency(
  name = "google-font-exo-2",
  version = "1.0.0",
  src = c(href = "https://fonts.googleapis.com/"),
  stylesheet = "css2?family=Exo+2:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
))
tags$style("body { font-family: 'Exo 2'; }")
```

I'd expect this to render properly, but instead it throws Error: path for html_dependency not provided.

singleton() not respected

I'd expect this to alert just once, but it alerts twice.

---
output: html_document
---

```{r echo=FALSE}
library(htmltools)
```
```{r}
tagList(
  singleton(tags$script('alert("hi");'))
)
```
```{r}
tagList(
  singleton(tags$script('alert("hi");'))
)
```

head() not respected

I'd expect this to alert, and for the script tag to be in the <head>, but it doesn't do anything.

---
output: html_document
---

```{r echo=FALSE}
library(htmltools)
```
```{r}
tagList(tags$head(tags$script('alert("hi");')))
```

xfun::session_info()
R version 4.0.0 (2020-04-24)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS, RStudio 1.4.437

Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
  LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
  LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
  LC_PAPER=en_US.UTF-8       LC_NAME=C                 
  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

Package version:
  assertthat_0.2.1  backports_1.1.7   base64enc_0.1.3  
  callr_3.4.3       cli_2.0.2         compiler_4.0.0   
  crayon_1.3.4      curl_4.3          desc_1.2.0       
  digest_0.6.25     evaluate_0.14     fansi_0.4.1      
  fs_1.4.1          glue_1.4.1        graphics_4.0.0   
  grDevices_4.0.0   highr_0.8         htmltools_0.4.0  
  jsonlite_1.6.1    knitr_1.28        magrittr_1.5     
  markdown_1.1      methods_4.0.0     mime_0.9         
  packrat_0.5.0-26  pkgbuild_1.0.8    prettyunits_1.1.1
  processx_3.4.2    ps_1.3.3          R6_2.4.1         
  Rcpp_1.0.4.6      remotes_2.1.1     rlang_0.4.6      
  rmarkdown_2.2.2   rprojroot_1.3-2   rstudioapi_0.11  
  stats_4.0.0       stringi_1.4.6     stringr_1.4.0    
  tinytex_0.23      tools_4.0.0       utils_4.0.0      
  withr_2.2.0       xfun_0.14         yaml_2.2.1

By filing an issue to this repo, I promise that

  • [x] I have fully read the issue guide at https://yihui.org/issue/.
  • [x] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('rmarkdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/rmarkdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [x] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

jcheng5 avatar Jun 08 '20 19:06 jcheng5

Thanks for raising these problems! For the record, #1805 tries to remove the first limitation, but I haven't had a chance to review it yet (well, I did briefly look at it but wasn't sure if it was worth introducing the dependency RCurl).

yihui avatar Jun 18 '20 03:06 yihui

I've forked & updated #1805 bc I agree with your concerns, I've raised it as a new PR #1948

strazto avatar Nov 12 '20 04:11 strazto

:eyes: @yihui @cderv

strazto avatar Apr 06 '21 12:04 strazto

Just to track progress, this issues cover 3 items we need to fix to close

  • [x] htmlDependencies with src=c(href="...") isn't supported -> Fixed by #2151
  • [ ] singleton() not respected
  • [ ] head() not respected https://github.com/rstudio/rmarkdown/issues/2475

cderv avatar May 31 '21 21:05 cderv