diff --git a/DESCRIPTION b/DESCRIPTION index 85ca5e6faa..9a8bdf9040 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rmarkdown Type: Package Title: Dynamic Documents for R -Version: 2.9.6 +Version: 2.9.7 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 e92e49a1f4..de216876be 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,9 @@ rmarkdown 2.10 - Ability to inject additional functions into Shiny prerendered server scope using the "server-extras" context. +- Fixed the syntax highlighting issue with R's pipe operator `|>` (thanks, @edzer, rstudio/bookdown#1157). + + rmarkdown 2.9 ================================================================================ diff --git a/R/html_document_base.R b/R/html_document_base.R index 3032fb6328..5504ff0b1e 100644 --- a/R/html_document_base.R +++ b/R/html_document_base.R @@ -158,14 +158,20 @@ html_document_base <- function(theme = NULL, } post_processor <- function(metadata, input_file, output_file, clean, verbose) { + # read the output file + output_str <- read_utf8(output_file) + + # TODO: remove this temporary fix after the syntax highlighting problem is + # fixed in Pandoc https://github.com/rstudio/bookdown/issues/1157 + s1 <- '|>' + s2 <- '=>' + # if there are no preserved chunks to restore and no resource to copy then no # post-processing is necessary - if (length(preserved_chunks) == 0 && !isTRUE(copy_resources) && self_contained) + if ((length(preserved_chunks) == 0 && !isTRUE(copy_resources) && self_contained) && + !length(c(grep(s1, output_str, fixed = TRUE), grep(s2, output_str, fixed = TRUE)))) return(output_file) - # read the output file - output_str <- read_utf8(output_file) - # if we preserved chunks, restore them if (length(preserved_chunks) > 0) { # Pandoc adds an empty
around the IDs of preserved chunks, and we @@ -203,6 +209,10 @@ html_document_base <- function(theme = NULL, output_str <- process_images(output_str, image_relative) } + # fix the issue mentioned in TODO above + output_str <- gsub(s1, '|>', output_str, fixed = TRUE) + output_str <- gsub(s2, '=>', output_str, fixed = TRUE) + write_utf8(output_str, output_file) output_file }