Skip to content

Commit

Permalink
Merge branch 'jg-devel'
Browse files Browse the repository at this point in the history
* jg-devel: (21 commits)
  Updated NEWS. Patched `merge_output_format_dependency` to ensure that named elements remain in the correct order.
  start the next version
  CRAN release v2.24
  shinyrmd: Safer dependency extraction from pre-rendered HTML (rstudio#2500)
  quote the version number per CRAN's request
  Add output_format_dependency() (rstudio#2462)
  file_scope is now correctly merged when creating output_format (rstudio#2488)
  Correctly run some tests only on CI
  start the next version
  CRAN release v2.23
  remove broken links
  suggest cleanrmd for e499bf7
  add news
  comparing version numbers with numbers is no longer allowed: https://bugs.r-project.org/show_bug.cgi?id=18548
  `find_external_resources` works with custom format using `theme` (rstudio#2494)
  start the next version
  CRAN release v2.22
  S3 generic/method consistency
  Change the code-folding button text from "Code" to "Show" (rstudio#2489)
  fix: bump jquery-ui to v1.13.2 to fix multiple CVEs (rstudio#2477)
  ...
  • Loading branch information
jonathan-g committed Aug 16, 2023
2 parents 2920cc6 + a10354c commit 5079b46
Show file tree
Hide file tree
Showing 50 changed files with 17,080 additions and 11,470 deletions.
5 changes: 3 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.21.4.9000
Version: 2.24.1.9000
Authors@R: c(
person("JJ", "Allaire", , "jj@posit.co", role = "aut"),
person("Yihui", "Xie", , "xie@yihui.name", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down Expand Up @@ -30,7 +30,7 @@ Authors@R: c(
person("Ruben", "Arslan", , "ruben.arslan@uni-goettingen.de", role = "ctb"),
person("Sergio", "Oller", role = "ctb"),
person(given = "Posit Software, PBC", role = c("cph", "fnd")),
person(, "jQuery UI contributors", role = c("ctb", "cph"), comment = "jQuery UI library; authors listed in inst/rmd/h/jqueryui-AUTHORS.txt"),
person(, "jQuery UI contributors", role = c("ctb", "cph"), comment = "jQuery UI library; authors listed in inst/rmd/h/jqueryui/AUTHORS.txt"),
person("Mark", "Otto", role = "ctb", comment = "Bootstrap library"),
person("Jacob", "Thornton", role = "ctb", comment = "Bootstrap library"),
person(, "Bootstrap contributors", role = "ctb", comment = "Bootstrap library"),
Expand Down Expand Up @@ -84,6 +84,7 @@ Suggests:
testthat (>= 3.0.3),
tibble,
vctrs,
cleanrmd,
withr (>= 2.4.2)
VignetteBuilder: knitr
Config/Needs/website: rstudio/quillt, pkgdown
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

S3method(knit_print,grouped_df)
S3method(knit_print,output_format_dependency)
S3method(knit_print,rowwise_df)
S3method(knit_print,tbl_sql)
S3method(prepare_evaluate_output,default)
Expand Down Expand Up @@ -57,6 +58,7 @@ export(navbar_html)
export(navbar_links_html)
export(odt_document)
export(output_format)
export(output_format_dependency)
export(output_metadata)
export(paged_table)
export(pandoc_available)
Expand Down
44 changes: 37 additions & 7 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,52 @@
rmarkdown 2.25
================================================================================

- `html_document` output allows `lib_dir` to point to a parent of the output
directory if the `allow_uptree_lib_dir` parameter is set to `TRUE`. This used
to throw an error, "The path <file> does not appear to be a descendant of
<dir>". This makes it possible to have a directory structure for HTML output
where there is a shared master library with css, javascript, etc. and separate
child directories with RMarkdown files. #146 and #1859.
(thanks, @jonathan-g, #2199)


rmarkdown 2.24
================================================================================

- Fixed `file_scope` being lost when extending output formats that considers the `file_scope` using `output_format()`. Merge behavior is to apply overlay `file_scope` function onto the result of `base_format`'s `file_scope` function. This implies that `file_scope` gains second argument which receives the returned values of the base `file_scope` (thanks, @atusy, #2488).

- Added `output_format_dependency()` which allows extending output format from within chunks (thanks, @atusy, #2462)

- Fix an issue with shiny prerendered document where dependencies context were written twice leasing to parsing error (thanks, @gadenbuie, rstudio/learn#597, #2500).


rmarkdown 2.23
================================================================================

- `find_external_resources()` works with formats defining there own `theme` argument, like `cleanrmd::html_document_clean()`, not related to **bslib** supports (thanks, @gadenbuie, #2493, r-lib/pkgdown#2319).

- Fixed version number comparison problems as requested by CRAN.


rmarkdown 2.22
================================================================================

- Using `css` with `.scss` and `.sass` file, or with a bslib theme, now works as expected with a shiny runtime (thanks, @cpsievert, #2443, #2447).

- Add a `pandoc_metadata_file_arg()` function to match Pandoc's CLI flag `--metadata-file`.

- Mentions that **webshot** or **webshot2** is required to take screenshot of HTML widget. When not installed, an error message mentionning `always_allow_html: true` solution will be shown, but setting this is not the solution (quarto-dev/quarto-cli#4225).

- `html_dependency_jqueryui()` updated to 1.13.2 from version bundled in shiny (thanks, @daschnerm, #2477).

- Fix an issue with YAML header ending with a commented line containing incomplete yaml (thanks, @keithnewman, #2483).

- When code folding is enabled in `html_document()`, the text on the button to show the content has been changed from "Code" to "Show", because the content to show is not necessarily code, e.g., yihui/knitr#2227.


rmarkdown 2.21
================================================================================

- `html_document` output allows `lib_dir` to point to a parent of the output
directory if the `allow_uptree_lib_dir` parameter is set to `TRUE`. This used
to throw an error, "The path <file> does not appear to be a descendant of
<dir>". This makes it possible to have a directory structure for HTML output
where there is a shared master library with css, javascript, etc. and separate
child directories with RMarkdown files. #146 and #1859.

- Now HTML output formats use the Font Awesome HTML dependency from the **fontawesome** package instead of shipping an outdated version of Font Awesome in **rmarkdown** (thanks, @rich-iannone, #2451).

- Fixed a bug caused by a change in the `is_blank()` function in **xfun** 0.38 (thanks, @andreahgsin, #2469).
Expand Down
11 changes: 4 additions & 7 deletions R/context_document.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#' Convert to a ConTeXt document
#'
#' Format for converting from R Markdown to PDF using
#' \href{https://wiki.contextgarden.net/Main_Page}{ConTeXt}.
#' Format for converting from R Markdown to PDF using ConTeXt.
#'
#' ConTeXt needs to be installed. To install the most recent version, see
#' \url{https://wiki.contextgarden.net/Installation}. A less recent version is
#' also available in TeX Live, you can install it with
#' ConTeXt needs to be installed, e.g., you can install it with
#' \code{tinytex::tlmgr_install("context")}.
#'
#' R Markdown documents can have optional metadata that is used to generate a
Expand All @@ -17,8 +14,8 @@
#' \href{https://pandoc.org/MANUAL.html#citations}{Bibliographies
#' and Citations} article in the online documentation.
#' @inheritParams pdf_document
#' @param context_path Path of the ConTeXt executable. If not provided, ConTeXt has
#' to be available from the \code{PATH} environment variable.
#' @param context_path Path of the ConTeXt executable. If not provided, ConTeXt
#' has to be available from the \code{PATH} environment variable.
#' @param context_args Command line arguments passed to ConTeXt.
#' @param ext Format of the output document (defaults to ".pdf").
#' @return R Markdown output format to pass to \code{\link{render}}.
Expand Down
7 changes: 6 additions & 1 deletion R/html_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ html_dependency_jqueryui <- function() {

htmlDependency(
name = "jqueryui",
version = "1.11.4",
version = version_jqueryui,
src = pkg_file("rmd/h/jqueryui"),
script = "jquery-ui.min.js")
}
Expand Down Expand Up @@ -84,6 +84,7 @@ bootstrap_dependencies <- function(theme) {
if (inherits(deps, "html_dependency")) list(deps) else deps
}

# resolves boostrap theme for bslib compatibility
resolve_theme <- function(theme) {
# theme = NULL means no Bootstrap
if (is.null(theme)) return(theme)
Expand Down Expand Up @@ -153,6 +154,10 @@ theme_version <- function(theme) {
substr(html_dependency_bootstrap("default")$version, 1, 1)
}

needs_sass <- function(css) {
grepl("\\.s[ac]ss$", css)
}


# Create an HTML dependency for tocify
#' @rdname html-dependencies
Expand Down
2 changes: 1 addition & 1 deletion R/html_document_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ html_document_base <- function(theme = NULL,

# Process css files as Pandoc argument if not already been processed by bslib
for (f in css) {
if (grepl("\\.s[ac]ss$", f)) {
if (needs_sass(f)) {
if (!xfun::loadable("sass")) {
stop2("Using `.sass` or `.scss` file in `css` argument requires the sass package.")
}
Expand Down
2 changes: 1 addition & 1 deletion R/html_paged.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ paged_table <- function(x, options = NULL) {
x
}

print.paged_df <- function(x) {
print.paged_df <- function(x, ...) {
knitr::asis_output(
paged_table_html(x, options = attr(x, "options")),
meta = list(
Expand Down
11 changes: 9 additions & 2 deletions R/html_resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ find_external_resources <- function(input_file, encoding = 'UTF-8') {
# ensure we're working with valid input
ext <- tolower(xfun::file_ext(input_file))
if (!(ext %in% c("md", "rmd", "qmd", "html", "htm", "r", "css"))) {
stop("Resource discovery is only supported for R Markdown files or HTML files.")
stop("Resource discovery is only supported for R Markdown, Quarto files or HTML (and CSS) files.")
}

if (!file.exists(input_file)) {
Expand Down Expand Up @@ -138,7 +138,7 @@ find_external_resources <- function(input_file, encoding = 'UTF-8') {
# clean row names (they're not meaningful)
rownames(discovered_resources) <- NULL

# convert paths from factors if necssary, and clean any redundant ./ leaders
# convert paths from factors if necessary, and clean any redundant ./ leaders
discovered_resources$path <- as.character(discovered_resources$path)
has_prefix <- grepl("^\\./", discovered_resources$path)
discovered_resources$path[has_prefix] <- substring(discovered_resources$path[has_prefix], 3)
Expand Down Expand Up @@ -216,6 +216,13 @@ discover_rmd_resources <- function(rmd_file, discover_single_resource) {
output_render_files <- unlist(output_format[c(
'includes', 'pandoc_args', 'logo', 'reference_doc', 'reference_docx', 'template'
)])
resolved_theme <- tryCatch(resolve_theme(output_format[["theme"]]), error = function(e) NULL)
# css needs to be copied for sass or bslib processing in formate rendering
needed <- if (is_bs_theme(resolved_theme)) TRUE else {
needs_sass(output_format[['css']])
}
output_render_files <- c(output_render_files, output_format[['css']][needed])

lapply(output_render_files, discover_render_resource)
}
}
Expand Down
2 changes: 1 addition & 1 deletion R/html_vignette.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ html_vignette <- function(fig_width = 3,
}

vignette_pre_processor <- function(input_file, metadata = yaml_front_matter(input_file)) {
if (getRversion() < 3.6)
if (getRversion() < '3.6')
return()
if (!getOption(o <- 'rmarkdown.html_vignette.check_title', !xfun::is_R_CMD_check()))
return()
Expand Down
2 changes: 1 addition & 1 deletion R/md_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ adapt_md_variant <- function(variant) {
gfm = ,
commonmark = ,
commonmark_x = {
if (pandoc_available(2.13)) {
if (pandoc_available("2.13")) {
set_extension(variant_extensions, "yaml_metadata_block", FALSE)
} else {
# Unsupported extension before YAML 2.13
Expand Down
97 changes: 94 additions & 3 deletions R/output_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
#' @param file_scope A function that will split markdown input to pandoc into
#' multiple named files. This is useful when the caller has concatenated a set
#' of Rmd files together (as \pkg{bookdown} does), and those files may need to
#' processed by pandoc using the \code{--file-scope} option. The function
#' should return a named list of files w/ \code{name} and \code{content} for
#' each file.
#' processed by pandoc using the \code{--file-scope} option. The first
#' argument is input file paths and the second is \code{NULL} or current file
#' scope which is a named list of files w/ \code{name} and \code{content} for
#' each file. The return is the new file scope. Also, the arguments should
#' include \code{...} for the future extensions.
#' @param base_format An optional format to extend.
#' @param allow_uptree_lib_dir Allow \code{lib_dir} output parameter not to
#' be a descendent of the output directory.
Expand Down Expand Up @@ -161,6 +163,27 @@ merge_post_processors <- function(base,
}
}

merge_file_scope <- function(base,
overlay) {
if (is.null(overlay)) {
return(base)
}
has_ellipsis <- "..." %in% names(formals(overlay))
if (!has_ellipsis) {
warning("file_scope lacks ... as an argument. ",
"Otherwise, file_scope replaces file_scope without merging.")
}
if (is.null(base) || !has_ellipsis) {
return(overlay)
}
if (has_ellipsis) {
return(function(x, current_scope = NULL, ...) {
scope <- base(x, current_scope, ...)
overlay(x, scope, ...)
})
}
}

# merges two output formats
merge_output_formats <- function(base,
overlay) {
Expand All @@ -187,6 +210,7 @@ merge_output_formats <- function(base,
overlay$intermediates_generator, c),
post_processor =
merge_post_processors(base$post_processor, overlay$post_processor),
file_scope = merge_file_scope(base$file_scope, overlay$file_scope),
on_exit =
merge_on_exit(base$on_exit, overlay$on_exit)
), class = "rmarkdown_output_format")
Expand Down Expand Up @@ -813,3 +837,70 @@ citeproc_required <- function(yaml_front_matter,
length(grep("^bibliography:\\s*$", input_lines)) > 0
)
}

#' Define an R Markdown's output format dependency
#'
#' Define the dependency such as and pre/post-processors dynamically from
#' within chunks. This function shares some arguments with
#' \code{\link{output_format}}, but lacks the others because dependency
#' is resolved after \code{post_knit} and before \code{pre_processor}.
#'
#' @param name A dependency name. If some dependencies share the same name,
#' then only the first one will be attached.
#' @inheritParams output_format
#' @return An list of arguments with the "rmd_dependency" class.
#' @examples
#' # Add lua filters from within a chunk
#' output_format_dependency("lua_filter", pre_processor = function(...) {
#' pandoc_lua_filter_args(c("example1.lua", "example2.lua"))
#' })
#'
#' @export
output_format_dependency <- function(name,
pandoc = list(),
pre_processor = NULL,
post_processor = NULL,
file_scope = NULL,
on_exit = NULL) {
# Some arguments are NULL
# to ensure inheriting the values from the base output format
structure(list(name = name,
knitr = NULL, # must be NULL because merge happens after knit
pandoc = pandoc,
pre_processor = pre_processor,
keep_md = NULL,
clean_supporting = NULL,
post_processor = post_processor,
file_scope = file_scope,
on_exit = on_exit),
class = "output_format_dependency")
}

#' @export
knit_print.output_format_dependency <- function(x, ...) {
knitr::asis_output(list(), meta = list(x))
}

merge_output_format_dependency <- function(fmt, dep) {
dep$name <- NULL # remove to be consistent with arguments of output_format
dep$base_format <- fmt
fmt2 <- do.call(output_format, dep)
cls <- class(fmt2)
# Make sure named elements are in the same order, to pass tests.
fmt2 <- fmt2[c(intersect(names(fmt), names(fmt2)),
setdiff(names(fmt), names(fmt2)),
setdiff(names(fmt2), names(fmt)))]
class(fmt2) <- cls
fmt2
}

merge_output_format_dependencies <- function(fmt, deps) {
skip <- c()
for (d in deps) {
if (inherits(d, "output_format_dependency") && !isTRUE(skip[d$name])) {
skip[d$name] <- TRUE
fmt <- merge_output_format_dependency(fmt, d)
}
}
fmt
}
9 changes: 8 additions & 1 deletion R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,9 @@ render <- function(input,

perf_timer_start("pre-processor")

if (has_dependencies(knit_meta, "output_format_dependency")) {
output_format <- merge_output_format_dependencies(output_format, knit_meta)
}
# call any pre_processor
if (!is.null(output_format$pre_processor)) {
extra_args <- output_format$pre_processor(front_matter,
Expand Down Expand Up @@ -1200,7 +1203,11 @@ resolve_df_print <- function(df_print) {
output_metadata = knitr:::new_defaults()

file_scope_split <- function(input, fun) {
inputs <- fun(input)
inputs <- if (length(formals(fun)) == 1L) {
fun(input) # for the backward compatibility
} else {
fun(input, NULL) # the second argument implies current file scope
}

# file_scope_fun should split the input file in several
# do nothing if not and return input file unsplited
Expand Down
Loading

0 comments on commit 5079b46

Please sign in to comment.