Skip to content

Commit 7c5fbb8

Browse files
committed
add the custom-environment.lua filter in common_format_config() instead of doing it for every single output format; this also make sure we won't need to do extra work in the future to support custom environments in other formats like Word and EPUB
1 parent 5233ec6 commit 7c5fbb8

File tree

4 files changed

+7
-34
lines changed

4 files changed

+7
-34
lines changed

R/gitbook.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,11 @@ gitbook = function(
3434
if (identical(template, 'default')) {
3535
template = bookdown_file('templates', 'gitbook.html')
3636
}
37-
3837
config = html_document2(
3938
toc = TRUE, number_sections = number_sections, fig_caption = fig_caption,
4039
self_contained = self_contained, lib_dir = lib_dir, theme = NULL,
4140
template = template, pandoc_args = pandoc_args2(pandoc_args), ...
4241
)
43-
44-
# add custom environment lua filter
45-
config = add_custom_environment_args(config)
46-
4742
split_by = match.arg(split_by)
4843
post = config$post_processor # in case a post processor have been defined
4944
config$post_processor = function(metadata, input, output, clean, verbose) {

R/html.R

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,11 @@ html_chapters = function(
5454
base_format = rmarkdown::html_document, split_bib = TRUE, page_builder = build_chapter,
5555
split_by = c('section+number', 'section', 'chapter+number', 'chapter', 'rmd', 'none')
5656
) {
57-
5857
config = get_base_format(base_format, list(
5958
toc = toc, number_sections = number_sections, fig_caption = fig_caption,
6059
self_contained = FALSE, lib_dir = lib_dir,
6160
template = template, pandoc_args = pandoc_args2(pandoc_args), ...
6261
))
63-
64-
# add custom environment lua filter
65-
config = add_custom_environment_args(config)
66-
6762
split_by = match.arg(split_by)
6863
post = config$post_processor # in case a post processor have been defined
6964
config$post_processor = function(metadata, input, output, clean, verbose) {
@@ -130,14 +125,9 @@ tufte_html_book = function(...) {
130125
html_document2 = function(
131126
..., number_sections = TRUE, pandoc_args = NULL, base_format = rmarkdown::html_document
132127
) {
133-
134128
config = get_base_format(base_format, list(
135129
..., number_sections = number_sections, pandoc_args = pandoc_args2(pandoc_args)
136130
))
137-
138-
# add custom environment lua filter
139-
config = add_custom_environment_args(config)
140-
141131
post = config$post_processor # in case a post processor have been defined
142132
config$post_processor = function(metadata, input, output, clean, verbose) {
143133
if (is.function(post)) output = post(metadata, input, output, clean, verbose)

R/latex.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ pdf_book = function(
3636
base_format = rmarkdown::pdf_document, toc_unnumbered = TRUE,
3737
toc_appendix = FALSE, toc_bib = FALSE, quote_footer = NULL, highlight_bw = FALSE
3838
) {
39-
4039
config = get_base_format(base_format, list(
4140
toc = toc, number_sections = number_sections, fig_caption = fig_caption,
4241
pandoc_args = pandoc_args2(pandoc_args), ...
4342
))
44-
45-
# add custom environment lua filter
46-
config = add_custom_environment_args(config)
47-
4843
config$pandoc$ext = '.tex'
4944
post = config$post_processor # in case a post processor have been defined
5045
config$post_processor = function(metadata, input, output, clean, verbose) {

R/utils.R

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ common_format_config = function(
3232
# provide file_scope if requested
3333
if (file_scope) config$file_scope = md_chapter_splitter
3434

35+
# prepend the custom-environment filter
36+
config$pandoc$lua_filters = c(
37+
lua_filter("custom-environment.lua"), config$pandoc$lua_filters
38+
)
39+
# and add bookdown metadata file for the filter to work
40+
config$pandoc$args = c(bookdown_yml_arg(), config$pandoc$args)
41+
3542
# set output format
3643
config$bookdown_output_format = format
3744

@@ -573,20 +580,6 @@ bookdown_yml_arg = function(config = load_config(), path = tempfile()) {
573580
c("--metadata-file", rmarkdown::pandoc_path_arg(path))
574581
}
575582

576-
# add custom environment filter to a format
577-
add_custom_environment_args = function(format) {
578-
if (!inherits(format, "rmarkdown_output_format"))
579-
stop("format should be a rmarkdown output format.")
580-
# prepend the filter
581-
format$pandoc$lua_filters = c(
582-
lua_filter("custom-environment.lua"), format$pandoc$lua_filters
583-
)
584-
# and add bookdown metadata file for the filter to work
585-
format$pandoc$args = c(bookdown_yml_arg(), format$pandoc$args)
586-
# return the modified format
587-
format
588-
}
589-
590583
#' Convert the syntax of theorem and proof environments from code blocks to
591584
#' fenced Divs
592585
#'

0 commit comments

Comments
 (0)