| 1 |
#' Include content within output |
| 2 |
#' |
| 3 |
#' Specify additional content to be included within an output document. |
| 4 |
#' |
| 5 |
#' Non-absolute paths for resources referenced from the |
| 6 |
#' \code{in_header}, \code{before_body}, and \code{after_body} |
| 7 |
#' parameters are resolved relative to the directory of the input document. |
| 8 |
#' @param in_header One or more files with content to be included in the |
| 9 |
#' header of the document. |
| 10 |
#' @param before_body One or more files with content to be included before |
| 11 |
#' the document body. |
| 12 |
#' @param after_body One or more files with content to be included after the |
| 13 |
#' document body. |
| 14 |
#' @param includes Includes to convert to pandoc args. |
| 15 |
#' @param filter Filter to pre-process includes with. |
| 16 |
#' @return Includes list or pandoc args |
| 17 |
#' @examples |
| 18 |
#' \dontrun{ |
| 19 |
#' library(rmarkdown) |
| 20 |
#' |
| 21 |
#' html_document(includes = includes(before_body = "header.htm")) |
| 22 |
#' |
| 23 |
#' pdf_document(includes = includes(after_body = "footer.tex")) |
| 24 |
#' } |
| 25 |
#' @name includes |
| 26 |
#' @export |
| 27 |
includes <- function(in_header = NULL, |
| 28 |
before_body = NULL, |
| 29 |
after_body = NULL) { |
| 30 |
|
| 31 |
list(in_header = in_header, |
| 32 |
before_body = before_body, |
| 33 |
after_body = after_body) |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
#' @rdname includes |
| 38 |
#' @export |
| 39 |
includes_to_pandoc_args <- function(includes, |
| 40 |
filter = identity) { |
| 41 |
if (!is.null(includes)) |
| 42 |
pandoc_include_args(in_header = filter(includes$in_header), |
| 43 |
before_body = filter(includes$before_body), |
| 44 |
after_body = filter(includes$after_body)) |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
# simple wrapper over normalizePath that preserves NULLs and applies pandoc- |
| 49 |
# friendly defaults |
| 50 |
normalize_path <- function(path, ..., must_work = NA) { |
| 51 |
if (!is.null(path)) xfun::normalize_path( |
| 52 |
path, ..., must_work = must_work, resolve_symlink = FALSE |
| 53 |
) |
| 54 |
} |