rstudio / htmltools

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

`htmlPreserve()` wraps input `<p>` tag in some cases #305

Closed cpsievert closed 2 years ago

cpsievert commented 2 years ago

Minimal reprex of the problem behind https://github.com/rstudio/flexdashboard/issues/379

This issue was introduced when we added the htmltools.preserve.raw in https://github.com/rstudio/htmltools/pull/191, which rmarkdown now sets to preserve HTML via pandoc's raw attributes rather than our using own hand-rolled solution.

What happens is essentially:

withr::with_options(
  list(htmltools.preserve.raw = TRUE), 
  htmlPreserve("<iframe></iframe>")
)
#> [1] "`<iframe></iframe>`{=html}"

And since this is using an inline code block, pandoc wraps the HTML in a <p>, which can have numerous unintended consequences, including changing the computed height on the input HTML (as we're seeing in https://github.com/rstudio/flexdashboard/issues/379)

# inline form
❯ pandoc -t html
`<iframe></iframe>`{=html}
^Z
<p><iframe></iframe></p>
# block form
❯ pandoc -t html
```{=html}
<iframe></iframe>

^Z



After running this through @jjallaire, it seems like the best way forward is to just not use the inline form at all since: 

1. It doesn't seem like there's any real use case for wrapping the input in `<p>` (and if there is, it seems easy enough to add it to the input?)
2. This should generally yield the same result as using `options(htmltools.preserve.raw = TRUE)`, which has been around much longer

cc @cderv