Skip to content

Commit 62ae2ed

Browse files
authored
Add output_format_filter function to default_site_generator(). (rstudio#1989)
Enables custom site generators to customize or even entirely replace the output format right before rendering of each page.
1 parent 433e726 commit 62ae2ed

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rmarkdown
22
Type: Package
33
Title: Dynamic Documents for R
4-
Version: 2.6.0002
4+
Version: 2.6.0003
55
Authors@R: c(
66
person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"),
77
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ rmarkdown 2.7
55

66
- Accept `latex="{options}"`, `latex=1`, or `latex=true` for Latex Divs.
77

8+
- Add `output_format_filter` function to `default_site_generator()`. Enables custom site generators to customize or even entirely replace the output format right before rendering of each page.
9+
10+
811
rmarkdown 2.6
912
================================================================================
1013

R/render_site.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,12 @@ site_config <- function(input = ".", encoding = "UTF-8") {
337337
# default site implementation (can be overridden by custom site generators)
338338

339339
#' @rdname render_site
340+
#' @param output_format_filter An optional function which is passed the
341+
#' input file and the output format, and which returns a (potentially
342+
#' modified) output format.
340343
#' @param ... Currently unused.
341344
#' @export
342-
default_site_generator <- default_site <- function(input, ...) {
345+
default_site_generator <- default_site <- function(input, output_format_filter = NULL, ...) {
343346

344347
# get the site config
345348
config <- site_config(input)
@@ -395,8 +398,14 @@ default_site_generator <- default_site <- function(input, ...) {
395398
# log the file being rendered
396399
if (!quiet) message("\nRendering: ", x)
397400

401+
# optionally customize the output format via filter
402+
file_output_format <- output_format
403+
if (!is.null(output_format_filter)) {
404+
file_output_format <- output_format_filter(x, output_format)
405+
}
406+
398407
output <- render_one(input = x,
399-
output_format = output_format,
408+
output_format = file_output_format,
400409
output_options = list(lib_dir = "site_libs",
401410
self_contained = FALSE),
402411
envir = envir,

man/render_site.Rd

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)