Skip to content

Commit

Permalink
Merged latest changes from RStudio fork.
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'rstudio/main' into jg-devel

* rstudio/main:
  Use new version of `has_crop_tools()` from knitr (rstudio#2532)
  some cosmetic changes
  use ignore.case = TRUE for regex functions instead of enumerating upper/lowercase letters
  Remove `stringr` dependency (rstudio#2530)
  Add a mention about required configuration when erroring about webshot and webshot2

# Conflicts:
#	NEWS.md
  • Loading branch information
jonathan-g committed Dec 19, 2023
2 parents 1c96a6a + 7187bd8 commit ca6f80b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 50 deletions.
14 changes: 1 addition & 13 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# CITATION file created with {cffr} R package, v0.4.1
# See also: https://docs.ropensci.org/cffr/
# -----------------------------------------------------------

cff-version: 1.2.0
message: 'To cite package "rmarkdown" in publications use:'
type: software
Expand Down Expand Up @@ -271,18 +271,6 @@ references:
year: '2023'
institution:
name: R Foundation for Statistical Computing
- type: software
title: stringr
abstract: 'stringr: Simple, Consistent Wrappers for Common String Operations'
notes: Imports
url: https://stringr.tidyverse.org
repository: https://CRAN.R-project.org/package=stringr
authors:
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2023'
version: '>= 1.2.0'
- type: software
title: tinytex
abstract: 'tinytex: Helper Functions to Install and Maintain TeX Live, and Compile
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ Imports:
htmltools (>= 0.5.1),
jquerylib,
jsonlite,
knitr (>= 1.22),
knitr (>= 1.43),
methods,
stringr (>= 1.2.0),
tinytex (>= 0.31),
tools,
utils,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ rmarkdown 2.26
child directories with RMarkdown files. #146 and #1859.
(thanks, @jonathan-g, #2199)

- **rmarkdown** now requires **knitr** >= 1.43.

- Get rid of the superfluous warning in `find_pandoc()` (thanks, @jszhao, #2527).

- Removed the **stringr** dependency since it is used only once in the package and the equivalent base R code is simple enough (thanks, @etiennebacher, #2530).

- For the output format option `fig_crop: auto`, it will now use the same logic as in **knitr** to decide if cropping is possible (yihui/knitr#2246).


rmarkdown 2.25
================================================================================
Expand Down
22 changes: 9 additions & 13 deletions R/base64.R
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
# processes an HTML resource, given a regular expression that locates
# instances of that resource
process_html_res <- function(html, reg, processor) {
html <- one_string(html)
process_img_src <- function(img_src) {
src <- sub(reg, '\\1', img_src)
m <- gregexpr(reg, html, perl = TRUE, ignore.case = TRUE)
regmatches(html, m) <- lapply(regmatches(html, m), function(img_src) {
src <- sub(reg, '\\1', img_src, ignore.case = TRUE)
vapply(
seq_along(img_src),
function(i) processor(img_src[[i]], src[[i]]),
character(1)
)
}
html <- stringr::str_replace_all(html, reg, process_img_src)
strsplit(html, "\n", fixed = TRUE)[[1]]
})
html
}

process_images <- function(html, processor) {
process_html_res(
html,
"<\\s*[Ii][Mm][Gg]\\s+.*?[Ss][Rr][Cc]\\s*=\\s*[\"']([^\"']+)[\"']",
processor)
process_html_res(html, "<\\s*img\\s+.*?src\\s*=\\s*[\"']([^\"']+)[\"']", processor)
}

base64_encode_images <- function(html) {
base64_encode_img <- function(img_src, src) {
encode <- function(img_src, src) {
in_file <- utils::URLdecode(src)
if (length(in_file) && file.exists(in_file)) {
img_src <- sub(src, xfun::base64_uri(in_file), img_src, fixed = TRUE)
}
img_src
}
html <- process_images(html, base64_encode_img)
process_html_res(html, "<[^>]*style=\"[^\"]*url\\(([^\\)]+)\\)", base64_encode_img)
html <- process_images(html, encode)
process_html_res(html, "<[^>]*style=\"[^\"]*url\\(([^\\)]+)\\)", encode)
}
2 changes: 1 addition & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ render <- function(input,
pandoc_to, " output.\nPlease change the output type ",
"of this document to HTML.\n",
"If your aiming to have some HTML widgets shown in non-HTML format as a screenshot,\n",
"please install webshot or webshot2 R package for knitr to do the screenshot.\n",
"please install webshot or webshot2 R package for knitr to do the screenshot, and configure it by looking at its documentation.\n",
"Alternatively, you can allow HTML output in non-HTML formats\n",
"by adding this option to the YAML front-matter of\nyour rmarkdown file:\n\n",
" always_allow_html: true\n\n",
Expand Down
15 changes: 1 addition & 14 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,20 +315,7 @@ find_program <- function(program) {
}
}

has_crop_tools <- function(warn = TRUE) {
tools <- c(
pdfcrop = unname(find_program("pdfcrop")),
ghostscript = unname(tools::find_gs_cmd())
)
missing <- tools[tools == ""]
if (length(missing) == 0) return(TRUE)
x <- paste0(names(missing), collapse = ", ")
if (warn) warning(
sprintf("\nTool(s) not installed or not in PATH: %s", x),
"\n-> As a result, figure cropping will be disabled."
)
FALSE
}
has_crop_tools <- function(...) knitr:::has_crop_tools(...)

# given a string, escape the regex metacharacters it contains:
# regex metas are these,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/site/PageA.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ knitr::opts_chunk$set(echo = TRUE)
Let's load a package (from existing dependencies) and make sure it's not on the search path when rendering a subsequent file.

```{r}
library(stringr)
library(tinytex)
plot(cars)
```

Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-site.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ test_that("render_site respects 'new_session' in the config", {
a <- readLines(file.path(site_dir, "_site", "PageA.html"))
b <- readLines(file.path(site_dir, "_site", "PageB.html"))

# pkg loaded in PageA (stringr) should show up in search path of PageB
expect_match(a, "library(stringr)", fixed = TRUE, all = FALSE)
expect_true(any(grepl("stringr", b, fixed = TRUE)))
# pkg loaded in PageA (tinytex) should show up in search path of PageB
expect_match(a, "library(tinytex)", fixed = TRUE, all = FALSE)
expect_true(any(grepl("tinytex", b, fixed = TRUE)))

# edit config --> new_session: true
cat("new_session: true", file = file.path(site_dir, "_site.yml"), append = TRUE)
Expand All @@ -77,9 +77,9 @@ test_that("render_site respects 'new_session' in the config", {
a <- readLines(file.path(site_dir, "_site", "PageA.html"))
b <- readLines(file.path(site_dir, "_site", "PageB.html"))

# pkg loaded in PageA (stringr) should NOT show up in search path of PageB
expect_match(a, "library(stringr)", fixed = TRUE, all = FALSE)
expect_false(any(grepl("stringr", b, fixed = TRUE)))
# pkg loaded in PageA (tinytex) should NOT show up in search path of PageB
expect_match(a, "library(tinytex)", fixed = TRUE, all = FALSE)
expect_false(any(grepl("tinytex", b, fixed = TRUE)))
})

test_that("clean_site gives notices before removing", {
Expand Down

0 comments on commit ca6f80b

Please sign in to comment.