Skip to content

Commit

Permalink
fix rstudio/bookdown#1157: correct the tags '<span class="sc">|</span…
Browse files Browse the repository at this point in the history
…><span class="er">&gt;</span>' and '<span class="ot">=</span><span class="er">&gt;</span>'
  • Loading branch information
yihui committed Jul 28, 2021
1 parent 9067a19 commit 99df4e7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
================================================================================

Expand Down
18 changes: 14 additions & 4 deletions R/html_document_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <- '<span class="sc">|</span><span class="er">&gt;</span>'
s2 <- '<span class="ot">=</span><span class="er">&gt;</span>'

# 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 <p></p> around the IDs of preserved chunks, and we
Expand Down Expand Up @@ -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, '<span class="sc">|&gt;</span>', output_str, fixed = TRUE)
output_str <- gsub(s2, '<span class="ot">=&gt;</span>', output_str, fixed = TRUE)

write_utf8(output_str, output_file)
output_file
}
Expand Down

0 comments on commit 99df4e7

Please sign in to comment.