From cf2522d27efe815bb430ae80044b92f3a94a10a5 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 16 Dec 2021 13:01:21 -0600 Subject: [PATCH 1/2] Close #305: don't use inline code blocks for pandocs raw attribute feature --- R/tags.R | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/R/tags.R b/R/tags.R index 40725689..07e14d3a 100644 --- a/R/tags.R +++ b/R/tags.R @@ -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("%s", 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("%s", x)) + } + # Always use the block (not inline) form since the latter wraps x in + # a

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 From 153c80efaf65fea959dd96c9fe86be17f2b2aa53 Mon Sep 17 00:00:00 2001 From: Carson Date: Thu, 16 Dec 2021 13:10:18 -0600 Subject: [PATCH 2/2] Update news --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 5cf447f7..0ed72717 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 `

` 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)