Skip to content

Commit

Permalink
Add output_format_filter function to default_site_generator(). (#…
Browse files Browse the repository at this point in the history
…1989)

Enables custom site generators to customize or even entirely replace the output format right before rendering of each page.
  • Loading branch information
jjallaire authored Dec 19, 2020
1 parent 433e726 commit 62ae2ed
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 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.6.0002
Version: 2.6.0003
Authors@R: c(
person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", 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 @@ -5,6 +5,9 @@ rmarkdown 2.7

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

- 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.


rmarkdown 2.6
================================================================================

Expand Down
13 changes: 11 additions & 2 deletions R/render_site.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,12 @@ site_config <- function(input = ".", encoding = "UTF-8") {
# default site implementation (can be overridden by custom site generators)

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

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

# optionally customize the output format via filter
file_output_format <- output_format
if (!is.null(output_format_filter)) {
file_output_format <- output_format_filter(x, output_format)
}

output <- render_one(input = x,
output_format = output_format,
output_format = file_output_format,
output_options = list(lib_dir = "site_libs",
self_contained = FALSE),
envir = envir,
Expand Down
6 changes: 5 additions & 1 deletion man/render_site.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 62ae2ed

Please sign in to comment.