Here are the examples of the r api knitr-knit_hooksget taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1 Examples
19
File: distill_article.R, author: rstudio, license: Apache License 2.0
knit_hooks < - function(downlit) {
previous_hooks < - knitr::knit_hooks$get()
on.exit(knitr::knit_hooks$restore(previous_hooks), add = TRUE)
knitr::render_markdown()
default_chunk_hook < - knitr::knit_hooks$get("chunk")
default_source_hook < - knitr::knit_hooks$get("source")
hooks < - list(chunk = function(x, options) {
if (is.null(options$layout)) options$layout < - "l-body"
output < - default_chunk_hook(x, options)
pad_chars < - nchar(output) - nchar(sub("^ +", "", output))
padding < - paste(rep(" ", pad_chars), collapse = "")
paste0(padding, " < div class=\"layout-chunk\" data-layout=\"",
options$layout, "\">\n", output, "\n", padding, "\n",
padding, " < /div>\n")
})
hooks$source < - function(x, options) {
code_folding < - not_null(options[["code_folding"]], FALSE)
if (downlit && options$engine == "R") {
code < - highlight(paste0(x, "\n", collapse = ""),
classes_pandoc(), pre_class = NULL)
if (is.na(code)) {
x < - default_source_hook(x, options)
}
else {
x < - paste0(" < div class=\"sourceCode\">", " < pre class=\"sourceCode r\">",
" < code class=\"sourceCode r\">", code, " < /code> < /pre> < /div>")
x < - paste0(x, "\n")
}
}
else {
x < - default_source_hook(x, options)
}
if (!identical(code_folding, FALSE)) {
if (identical(code_folding, TRUE)) {
code_folding < - "Show code"
}
else {
code_folding < - as.character(code_folding)
}
x < - paste0(" < details>\n < summary>", code_folding,
" < /summary>\n", x, "\n < /details>")
}
x
}
if (downlit) {
hooks$document < - function(x, options) {
c(x, "```{.r .distill-force-highlighting-css}", "```")
}
}
hooks
}