rstudio / htmltools

Tools for HTML generation and output
https://rstudio.github.io/htmltools/
214 stars 67 forks source link

Support directly including `htmlDependency()` objects in rmarkdown #376

Closed gadenbuie closed 1 year ago

gadenbuie commented 1 year ago

This PR fixes #375, making it possible to include an htmlDependency() simply by calling it in an R chunk where it's handled by knit_print().

Previously, users had to include the dependency in a tagList() or a tag to use the knit_print.shiny.tag method. Fortunately, that same method works for htmlDependency() objects too.

This small R Markdown document will now show the pencil icon, where previously it would print the font awesome dependency and no icon would be visible.

---
title: Issue 375
---

```{r}
library(htmltools)

fontawesome::fa_html_dependency()
tags$i(class = "fas fa-pencil")
print(fontawesome::fa_html_dependency())


This is a _slightly_ breaking change in the sense that users who were previously printing the html dependency will now need to use `print()` explicitly to show the object structure. In general, I think the new behavior is preferable.
gadenbuie commented 1 year ago

@schloerke I added skip_if_not_installed("knitr") to the test I added around this change, should we ensure knitr is installed in CI for r-cmd-check? It currently isn't due to knitr being an Enhances dependency

schloerke commented 1 year ago

Good catch!

schloerke commented 1 year ago

Yes, let's add it in Config/needs/check: knitr in the DESCRIPTION file. (Similar to Config/needs/website)