diff --git a/DESCRIPTION b/DESCRIPTION index da0ec0513b..a3bdb7f769 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rmarkdown Type: Package Title: Dynamic Documents for R -Version: 2.11.2 +Version: 2.11.3 Authors@R: c( person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"), person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")), diff --git a/NEWS.md b/NEWS.md index a94af13a59..8e2fecfa4d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ rmarkdown 2.12 where there is a shared master library with css, javascript, etc. and separate child directories with RMarkdown files. #146 and #1859. +- Added a global option `rmarkdown.html_dependency.header_attr` (`TRUE` by default). It can be set to `FALSE` to opt-out the HTML dependency `html_dependency_header_attrs()` in documents based on `html_document_base()` (thanks, @salim-b rstudio/bookdown#865, @maelle r-lib/downlit#1538). + - `draft()` now works with `devtools::load_all()` and **testthat** when used in other packages. rmarkdown 2.11 diff --git a/R/html_dependencies.R b/R/html_dependencies.R index 802cb4e06b..5d12186216 100644 --- a/R/html_dependencies.R +++ b/R/html_dependencies.R @@ -553,12 +553,14 @@ html_dependency_rsiframe <- function() { # Pandoc 2.9 adds attributes on both headers and their parent divs. We remove # the ones on headers since they are unnecessary (#1723). html_dependency_header_attrs <- function() { - if (pandoc_available('2.9')) list( - htmlDependency( - "header-attrs", - version = packageVersion("rmarkdown"), - src = pkg_file("rmd/h/pandoc"), - script = "header-attrs.js" + if (getOption('rmarkdown.html_dependency.header_attr', TRUE) && pandoc_available('2.9')) { + list( + htmlDependency( + "header-attrs", + version = packageVersion("rmarkdown"), + src = pkg_file("rmd/h/pandoc"), + script = "header-attrs.js" + ) ) - ) + } } diff --git a/R/pdf_document.R b/R/pdf_document.R index 77c2b8d99c..4b9f5287b4 100644 --- a/R/pdf_document.R +++ b/R/pdf_document.R @@ -188,6 +188,17 @@ pdf_document <- function(toc = FALSE, output_dir) } + post_processor <- function(metadata, input_file, output_file, clean, verbose) { + # TODO: remove this temporary fix after the syntax highlighting problem is + # fixed in Pandoc https://github.com/rstudio/bookdown/issues/1157 + x <- read_utf8(output_file) + s <- '\\SpecialCharTok{|}\\ErrorTok{\\textgreater{}}' + if (length(grep(s, x, fixed = TRUE)) == 0) return(output_file) + x <- gsub(s, '\\SpecialCharTok{|\\textgreater{}}', x, fixed = TRUE) + write_utf8(x, output_file) + output_file + } + intermediates_generator <- function(...) { general_intermediates_generator(saved_files_dir, ...) } @@ -207,6 +218,7 @@ pdf_document <- function(toc = FALSE, keep_md = keep_md, df_print = df_print, pre_processor = pre_processor, + post_processor = post_processor, intermediates_generator = intermediates_generator ) } diff --git a/README.md b/README.md index 0f46525485..9c39759303 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,8 @@ R Markdown documents can be rendered to many output formats including HTML docum ## Books - -R Markdown: The Definitive Guide -R Markdown Cookbook +R Markdown: The Definitive Guide +R Markdown Cookbook See more about them in [Get Started](https://pkgs.rstudio.com/rmarkdown/articles/rmarkdown.html). diff --git a/tests/testthat/test-html_dependencies.R b/tests/testthat/test-html_dependencies.R index 5149f5a9a3..62f83a70fb 100644 --- a/tests/testthat/test-html_dependencies.R +++ b/tests/testthat/test-html_dependencies.R @@ -196,3 +196,8 @@ test_that("html_dependencies_fonts loads the correct fonts dep", { expect_identical(html_dependencies_fonts(FALSE, TRUE), list(io)) expect_identical(html_dependencies_fonts(TRUE, TRUE), list(fa, io)) }) + +test_that("header-attr can be opt-out", { + withr::local_options(list(rmarkdown.html_dependency.header_attr = FALSE)) + expect_null(html_dependency_header_attrs()) +})