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

Don't use inline code blocks for pandocs raw attribute feature #306

Merged
merged 2 commits into from
Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# htmltools 0.5.2.9000

## Breaking changes

* Closed #305: `htmlPreserve()` no longer uses inline code blocks for Pandoc's raw attribute feature (i.e., when `options(htmltools.preserve.raw = TRUE)`. As a result, rmarkdown no longer adds an addition `<p>` tag around 'literal' HTML. (#306)

## Bug fixes

* Closed #301: `tagQuery()` was failing to copy all `tagList()` html dependencies within nest child tag lists. `tagQuery()` will now relocate html dependencies as child objects. (#302)
Expand Down
30 changes: 15 additions & 15 deletions R/tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -1482,22 +1482,22 @@ as.tags.html_dependency <- function(x, ...) {
#'
#' @export
htmlPreserve <- function(x) {
raw = getOption("htmltools.preserve.raw", FALSE)
x <- paste(x, collapse = "\n")
if (nzchar(x))
if (raw) {
# use fenced code block if there are embedded newlines
if (grepl("\n", x, fixed = TRUE))
sprintf("\n```{=html}\n%s\n```\n", x)
# otherwise use inline span
else
sprintf("`%s`{=html}", x)
}
else {
sprintf("<!--html_preserve-->%s<!--/html_preserve-->", x)
}
else
x
# Do nothing for empty string
if (!nzchar(x)) {
return(x)
}
# rmarkdown sets this option to TRUE to leverage various benefits
# that come with preserving HTML via pandoc 2.0's raw attribute feature
# https://github.com/rstudio/rmarkdown/pull/1965#issuecomment-734804176
if (!getOption("htmltools.preserve.raw", FALSE)) {
return(sprintf("<!--html_preserve-->%s<!--/html_preserve-->", x))
}
# Always use the block (not inline) form since the latter wraps x in
# a <p> tag, which can have unfortunate consequences, most notably
# https://github.com/rstudio/flexdashboard/issues/379
# https://github.com/rstudio/rmarkdown/issues/2259#issuecomment-995996958
sprintf("\n```{=html}\n%s\n```\n", x)
}

# Temporarily set x in env to value, evaluate expr, and
Expand Down