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