Skip to content

Commit

Permalink
Merged RStudio rmarkdown 2.20 release.
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'rstudio/main' into jg-devel

# By Yihui Xie (3) and others
# Via Yihui Xie
* rstudio/main:
  start the next version
  CRAN release v2.20
  make sure `ioslides_presentation` is properly self-contained when requested (rstudio#2428)
  More tests needs fixing
  Newer Pandoc (currently devel) fixes GFM toc previously written in HTML instead of Markdown
  make sure to avoid creating invalid paths when copying resources (rstudio#2429)
  Fix rstudio#1508: do not resolve input files that are symlinks (rstudio#2438)

# Conflicts:
#	DESCRIPTION
  • Loading branch information
jonathan-g committed Jan 20, 2023
2 parents 2bdccfd + ca5824a commit 57a741d
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 14 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: rmarkdown
Title: Dynamic Documents for R
Version: 2.19.2.9000
Version: 2.20.1.9000
Authors@R: c(
person("JJ", "Allaire", , "[email protected]", role = "aut"),
person("Yihui", "Xie", , "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down Expand Up @@ -69,7 +69,7 @@ Imports:
tinytex (>= 0.31),
tools,
utils,
xfun (>= 0.30),
xfun (>= 0.36),
yaml (>= 2.1.19)
Suggests:
digest,
Expand Down
12 changes: 11 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rmarkdown 2.20
rmarkdown 2.21
================================================================================

- `html_document` output allows `lib_dir` to point to a parent of the output
Expand All @@ -8,8 +8,18 @@ rmarkdown 2.20
where there is a shared master library with css, javascript, etc. and separate
child directories with RMarkdown files. #146 and #1859.


rmarkdown 2.20
================================================================================

- The defunct `tufte_handout()` has been removed from **rmarkdown**. Please use `tufte::tufte_handout()` instead.

- If an input path to `rmarkdown::render()` is a symbolic link, it is no longer resolved to its real path (thanks, @SamDM @jmw86069, #1508).

- Make sure to avoid creating invalid paths when copying resources (thanks, @mnazarov, #2429).

- Make sure `logo` is properly embedded in `ioslides_presentation()` when `self_contained = TRUE` (thanks, @mnazarov, #2428).


rmarkdown 2.19
================================================================================
Expand Down
12 changes: 10 additions & 2 deletions R/html_resource_copy.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ copy_html_resources <- function(html_str, lib_dir, output_dir) {
copy_resources(html_str, lib_dir, output_dir, resource_locator)
}

make_abs_path_safe <- function(path) {
if (xfun::is_windows()) {
sub("^.:(/|\\\\)*", "", path) # windows
} else {
sub("^[/]*", "", path) # *nix
}
}

copy_resources <- function(input_str, lib_dir, output_dir, resource_locator) {
# ensure the lib directory exists
dir.create(lib_dir, recursive = TRUE, showWarnings = FALSE)
Expand All @@ -49,7 +57,7 @@ copy_resources <- function(input_str, lib_dir, output_dir, resource_locator) {
target_dir <- if (dirname(in_file) == ".")
lib_dir
else
file.path(lib_dir, dirname(in_file))
file.path(lib_dir, make_abs_path_safe(dirname(in_file)))
dir.create(target_dir, recursive = TRUE, showWarnings = FALSE)
target_res_file <- file.path(target_dir, basename(in_file))

Expand All @@ -61,7 +69,7 @@ copy_resources <- function(input_str, lib_dir, output_dir, resource_locator) {
if (identical(lib_dir, output_dir))
res_src <- in_file
else
res_src <- file.path(relative_lib, src)
res_src <- file.path(relative_lib, make_abs_path_safe(src))
} else {
# inside the library, fix up the URL
res_src <- file.path(relative_lib, res_src)
Expand Down
6 changes: 4 additions & 2 deletions R/includes.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ includes_to_pandoc_args <- function(includes,

# simple wrapper over normalizePath that preserves NULLs and applies pandoc-
# friendly defaults
normalize_path <- function(path, winslash = "/", must_work = NA) {
if (!is.null(path)) normalizePath(path, winslash = winslash, mustWork = must_work)
normalize_path <- function(path, ..., must_work = NA) {
if (!is.null(path)) xfun::normalize_path(
path, ..., must_work = must_work, resolve_symlink = FALSE
)
}
15 changes: 11 additions & 4 deletions R/ioslides_presentation.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ ioslides_presentation <- function(number_sections = FALSE,
if (!length(grep('--wrap', pandoc_args)))
pandoc_args <- c('--wrap', 'none', pandoc_args)

logo_placeholder <- "data:,LOGO"

# pre-processor for arguments that may depend on the name of the
# the input file (e.g. ones that need to copy supporting files)
pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
Expand Down Expand Up @@ -360,7 +362,8 @@ ioslides_presentation <- function(number_sections = FALSE,
file.copy(from = logo, to = logo_path)
logo_path <- normalized_relative_to(output_dir, logo_path)
} else {
logo_path <- pandoc_path_arg(logo_path)
# placeholder, will be replaced by base64-encoded logo in post_processor
logo_path <- logo_placeholder
}
args <- c(args, "--variable", paste("logo=", logo_path, sep = ""))
}
Expand Down Expand Up @@ -450,14 +453,18 @@ ioslides_presentation <- function(number_sections = FALSE,
# read the slides
slides_lines <- read_utf8(output_tmpfile)

# read the output file
output_lines <- read_utf8(output_file)

# base64 encode if needed
if (self_contained) {
slides_lines <- base64_encode_images(slides_lines)
if (!is.null(logo)) {
logo_base64 <- if (grepl("^data:", logo)) logo else xfun::base64_uri(logo)
output_lines <- gsub(logo_placeholder, logo_base64, output_lines, fixed = TRUE)
}
}

# read the output file
output_lines <- read_utf8(output_file)

# substitute slides for the sentinel line
sentinel_line <- grep("^RENDERED_SLIDES$", output_lines)
if (length(sentinel_line) == 1) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- [1 Section](#1-section)
- [2 Header](#2-header)

# 1 Section

Sentence.

# 2 Header

Sentence
11 changes: 11 additions & 0 deletions tests/testthat/_snaps/pandoc-3/github_document/github-toc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- [10 Section](#10-section)
- [Header](#header)

# 10 Section

Sentence.

# Header

Sentence
44 changes: 44 additions & 0 deletions tests/testthat/_snaps/pandoc-3/lua-filters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# number_sections Lua filter works

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#a)

---

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#1-a)

---

Test
================

- [1 A](#1-a)
- [1.1 B](#11-b)
- [2 C](#2-c)
- [2.1 D](#21-d)

# 1 A

## 1.1 B

# 2 C

## 2.1 D

See [A](#1-a)

8 changes: 6 additions & 2 deletions tests/testthat/test-github_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ test_that("toc has correct identifier", {
tmp_file <- local_rmd_file(
c("# 10 Section","","Sentence.","", "# Header","","Sentence ")
)
pandoc_version <- if (pandoc_available("2.18.0.1")) {
pandoc_version <- if (pandoc_available("3")) {
"pandoc-3"
} else if (pandoc_available("2.18.0.1")) {
"after-pandoc-2.18"
} else if (pandoc_available("2.18")) {
"pandoc-2.18"
Expand All @@ -24,7 +26,9 @@ test_that("toc has correct identifier also when sections are numbered ", {
tmp_file <- local_rmd_file(
c("# Section","","Sentence.","", "# Header","","Sentence ")
)
pandoc_version <- if (pandoc_available("2.18.0.1")) {
pandoc_version <- if (pandoc_available("3")) {
"pandoc-3"
} else if (pandoc_available("2.18.0.1")) {
"after-pandoc-2.18"
} else if (pandoc_available("2.18")) {
"pandoc-2.18"
Expand Down
28 changes: 28 additions & 0 deletions tests/testthat/test-ioslides.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,31 @@ test_ioslides_presentation_css <- function() {


test_that("ioslides presentation is styled", test_ioslides_presentation_css())

test_ioslides_presentation_logo <- function() {

outputdir <- tempfile()
dir.create(outputdir)
on.exit(unlink(outputdir), add = TRUE)

# Generate mock md file with logo
void <- file.copy("resources/empty.png", file.path(outputdir, "logo.png"))
mdtext <- c("# Slide One\n")
mock <- mock_markdown(mdtext = mdtext, outputdir = outputdir, self_contained = TRUE, logo = "logo.png")
html <- mock$html_file

slide_lines <- c(
!any(grepl("logo\\.png", html))
, any(grep("favIcon: 'data:image/png;base64,[^']*'", html))
, any(grepl("background: url\\(data:image/png;base64,[^\\)]*)", html))
)
expect_true(all(slide_lines), info = "slide lines - self contained logo")

# if logo is passed as base64 string, do not re-encode
logobase64 <- xfun::base64_uri("resources/empty.png")
mock2 <- mock_markdown(mdtext = mdtext, outputdir = outputdir, self_contained = TRUE, logo = logobase64)
html2 <- mock2$html_file
expect_equal(html, html2)
}

test_that("ioslides presentation embeds logo", test_ioslides_presentation_logo())
4 changes: 3 additions & 1 deletion tests/testthat/test-lua-filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ test_that("number_sections Lua filter works", {
headers <- c("# A", "## B", "# C", "## D")
rmd <- c(paste0(headers, "\n\n"), "See [A]")
# Variant for snapshot: pandoc 2.11.2 default to atx headers
pandoc_versions <- if (pandoc_available("2.18.0.1")) {
pandoc_versions <- if (pandoc_available("3")) {
"pandoc-3"
} else if (pandoc_available("2.18.0.1")) {
"after-pandoc-2.18"
} else if (pandoc_available("2.18")) {
"pandoc-2.18"
Expand Down

0 comments on commit 57a741d

Please sign in to comment.