redoc modifies R Markdown documents prior to knitting to capture and store document elements that will need to be restored later. It does this via a function passed to the pre_knit argument of rmarkdown::output_format(). make_preknitter generates this function from a list of wrapper functions.

make_preknitter(wrappers = list())

Arguments

wrappers

a list of wrapper functions.

Value

A function to be used in `output_format(pre_knit = ...)``

Details

rmarkdown does not provide a mechanism to modify the file prior to knitting, so redoc accomplishes this by reaching up the call stack and modifying the environment in the rmarkdown::render() function. The function generated by make_preknitter will do this by generating the pre-processed R Markdown file and associated list of code chunks, adding these the list of intermediates for cleanup, and switching the document input to this pre-processed document.

Examples

make_preknitter(wrappers = list(htmlcommentwrap, latexwrap))
#> function (input, ...) #> { #> render_env <- get_parent_env_with("knit_input") #> pre_knit_input <- get("knit_input", envir = render_env) #> intermediates_loc <- get("intermediates_loc", envir = render_env) #> rmd_text <- normalize_newlines(readfile(input)) #> rmd <- wrap_code(rmd_text, wrappers = wrappers) #> codefile <- intermediates_loc(file_with_meta_ext(basename(input), #> "codelist", "yml")) #> preprocessed_rmd_file <- intermediates_loc(file_with_meta_ext(pre_knit_input, #> "preprocessed")) #> write_yaml(rmd$code, codefile) #> cat(rmd$text, file = preprocessed_rmd_file) #> assign("knit_input", preprocessed_rmd_file, envir = render_env) #> add_intermediates(c(codefile, preprocessed_rmd_file)) #> } #> <bytecode: 0x582e218> #> <environment: 0x58302c0>