JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 1 | #' Convert to a reveal.js presentation |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 2 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 3 | #' Format for converting from R Markdown to a reveal.js presentation. |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 4 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 5 | #' @inheritParams rmarkdown::beamer_presentation |
| 6 | #' @inheritParams rmarkdown::pdf_document |
| 7 | #' @inheritParams rmarkdown::html_document |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 8 | #' |
Christophe Dervieux | 21239cf | 2021-09-15 15:34:01 +0200 | [diff] [blame] | 9 | #' @param smart Produce typographically correct output, converting straight |
| 10 | #' quotes to curly quotes, \code{---} to em-dashes, \code{--} to en-dashes, and |
| 11 | #' \code{...} to ellipses. |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 12 | #' @param center \code{TRUE} to vertically center content on slides |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 13 | #' @param slide_level Level of heading to denote individual slides. If |
| 14 | #' \code{slide_level} is 2 (the default), a two-dimensional layout will be |
| 15 | #' produced, with level 1 headers building horizontally and level 2 headers |
| 16 | #' building vertically. It is not recommended that you use deeper nesting of |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 17 | #' section levels with reveal.js. |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 18 | #' @param theme Visual theme ("simple", "sky", "beige", "serif", "solarized", |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 19 | #' "blood", "moon", "night", "black", "league" or "white"). |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 20 | #' @param transition Slide transition ("default", "none", "fade", "slide", |
junkka | d4b3a16 | 2015-03-16 07:49:11 +0100 | [diff] [blame] | 21 | #' "convex", "concave" or "zoom") |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 22 | #' @param background_transition Slide background-transition ("default", "none", |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 23 | #' "fade", "slide", "convex", "concave" or "zoom") |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 24 | #' @param reveal_options Additional options to specify for reveal.js (see |
Atsushi Yasumoto | 66c5585 | 2020-08-10 21:50:04 +0900 | [diff] [blame] | 25 | #' \href{https://revealjs.com/config/}{https://revealjs.com/config/} |
JJ Allaire | 35c0b49 | 2017-02-10 09:30:24 -0500 | [diff] [blame] | 26 | #' for details). |
| 27 | #' @param reveal_plugins Reveal plugins to include. Available plugins include |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 28 | #' "notes", "search", "zoom", "chalkboard", and "menu". Note that |
JJ Allaire | 35c0b49 | 2017-02-10 09:30:24 -0500 | [diff] [blame] | 29 | #' \code{self_contained} must be set to \code{FALSE} in order to use Reveal |
| 30 | #' plugins. |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 31 | #' @param template Pandoc template to use for rendering. Pass "default" to use |
| 32 | #' the rmarkdown package default template; pass \code{NULL} to use pandoc's |
| 33 | #' built-in template; pass a path to use a custom template that you've |
| 34 | #' created. Note that if you don't use the "default" template then some |
| 35 | #' features of \code{revealjs_presentation} won't be available (see the |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 36 | #' Templates section below for more details). |
JJ Allaire | 35c0b49 | 2017-02-10 09:30:24 -0500 | [diff] [blame] | 37 | #' @param extra_dependencies Additional function arguments to pass to the base R |
| 38 | #' Markdown HTML output formatter [rmarkdown::html_document_base()]. |
JJ Allaire | 8d1c2f4 | 2016-01-30 14:56:45 -0500 | [diff] [blame] | 39 | #' @param ... Ignored |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 40 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 41 | #' @return R Markdown output format to pass to \code{\link{render}} |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 42 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 43 | #' @details |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 44 | #' |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 45 | #' In reveal.js presentations you can use level 1 or level 2 headers for slides. |
| 46 | #' If you use a mix of level 1 and level 2 headers then a two-dimensional layout |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 47 | #' will be produced, with level 1 headers building horizontally and level 2 |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 48 | #' headers building vertically. |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 49 | #' |
| 50 | #' For additional documentation on using revealjs presentations see |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 51 | #' \href{https://github.com/rstudio/revealjs}{https://github.com/rstudio/revealjs}. |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 52 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 53 | #' @examples |
| 54 | #' \dontrun{ |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 55 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 56 | #' library(rmarkdown) |
| 57 | #' library(revealjs) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 58 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 59 | #' # simple invocation |
| 60 | #' render("pres.Rmd", revealjs_presentation()) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 61 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 62 | #' # specify an option for incremental rendering |
| 63 | #' render("pres.Rmd", revealjs_presentation(incremental = TRUE)) |
| 64 | #' } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 65 | #' |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 66 | #' @export |
| 67 | revealjs_presentation <- function(incremental = FALSE, |
| 68 | center = FALSE, |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 69 | slide_level = 2, |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 70 | fig_width = 8, |
| 71 | fig_height = 6, |
| 72 | fig_retina = if (!fig_caption) 2, |
| 73 | fig_caption = FALSE, |
| 74 | smart = TRUE, |
| 75 | self_contained = TRUE, |
JJ Allaire | 6da1bb6 | 2016-01-30 14:28:39 -0500 | [diff] [blame] | 76 | theme = "simple", |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 77 | transition = "default", |
junkka | d55cff0 | 2015-03-15 22:27:03 +0100 | [diff] [blame] | 78 | background_transition = "default", |
JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 79 | reveal_options = NULL, |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 80 | reveal_plugins = NULL, |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 81 | highlight = "default", |
| 82 | mathjax = "default", |
| 83 | template = "default", |
JJ Allaire | fad5523 | 2015-10-19 07:47:26 -0400 | [diff] [blame] | 84 | css = NULL, |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 85 | includes = NULL, |
| 86 | keep_md = FALSE, |
| 87 | lib_dir = NULL, |
| 88 | pandoc_args = NULL, |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 89 | extra_dependencies = NULL, |
Atsushi Yasumoto | 0bf4444 | 2020-02-15 00:08:30 +0900 | [diff] [blame] | 90 | md_extensions = NULL, |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 91 | ...) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 92 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 93 | # base pandoc options for all reveal.js output |
| 94 | args <- c() |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 95 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 96 | # template path and assets |
JJ Allaire | a8c414b | 2016-01-30 14:36:53 -0500 | [diff] [blame] | 97 | if (identical(template, "default")) { |
christophe dervieux | 92fa469 | 2021-09-21 16:15:17 +0200 | [diff] [blame] | 98 | default_template <- reveal_resources("default.html") |
JJ Allaire | a8c414b | 2016-01-30 14:36:53 -0500 | [diff] [blame] | 99 | args <- c(args, "--template", pandoc_path_arg(default_template)) |
| 100 | } else if (!is.null(template)) { |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 101 | args <- c(args, "--template", pandoc_path_arg(template)) |
JJ Allaire | a8c414b | 2016-01-30 14:36:53 -0500 | [diff] [blame] | 102 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 103 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 104 | # incremental |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 105 | if (incremental) args <- c(args, "--incremental") |
| 106 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 107 | # centering |
JJ Allaire | 40fec33 | 2016-01-30 16:54:51 -0500 | [diff] [blame] | 108 | args <- c(args, pandoc_variable_arg("center", jsbool(center))) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 109 | |
JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 110 | # slide level |
JJ Allaire | c58a6c4 | 2016-03-30 23:45:21 -0400 | [diff] [blame] | 111 | args <- c(args, "--slide-level", as.character(slide_level)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 112 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 113 | # theme |
| 114 | theme <- match.arg(theme, revealjs_themes()) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 115 | if (identical(theme, "default")) { |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 116 | theme <- "simple" |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 117 | } else if (identical(theme, "dark")) { |
JJ Allaire | 6da1bb6 | 2016-01-30 14:28:39 -0500 | [diff] [blame] | 118 | theme <- "black" |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 119 | } |
| 120 | if (theme %in% c("blood", "moon", "night", "black")) { |
christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 121 | args <- c(args, pandoc_variable_arg("theme-dark")) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 122 | } |
christophe dervieux | 1ebd513 | 2021-09-22 08:47:21 +0200 | [diff] [blame^] | 123 | args <- c(args, pandoc_variable_arg("theme", theme)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 124 | |
| 125 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 126 | # transition |
| 127 | transition <- match.arg(transition, revealjs_transitions()) |
christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 128 | args <- c(args, pandoc_variable_arg("transition", transition)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 129 | |
junkka | d55cff0 | 2015-03-15 22:27:03 +0100 | [diff] [blame] | 130 | # background_transition |
| 131 | background_transition <- match.arg(background_transition, revealjs_transitions()) |
christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 132 | args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 133 | |
JJ Allaire | 4ae486f | 2016-03-23 06:08:42 -0400 | [diff] [blame] | 134 | # use history |
| 135 | args <- c(args, pandoc_variable_arg("history", "true")) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 136 | |
JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 137 | # additional reveal options |
| 138 | if (is.list(reveal_options)) { |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 139 | add_reveal_option <- function(option, value) { |
atusy | 0e3a0d3 | 2021-09-16 19:52:35 +0900 | [diff] [blame] | 140 | if (is.logical(value)) { |
JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 141 | value <- jsbool(value) |
atusy | 0e3a0d3 | 2021-09-16 19:52:35 +0900 | [diff] [blame] | 142 | } else if (is.character(value)) { |
| 143 | # Special handling for some chalkboard plugin options |
| 144 | # e.g: color: [ 'rgba(0,0,255,1)', 'rgba(255,255,255,0.5)' ] |
| 145 | if (grepl("chalkboard-(background|color|draw|pen)", option)) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 146 | value <- sprintf("[%s]", paste(paste0("'", value, "'"), collapse = ", ")) |
atusy | 0e3a0d3 | 2021-09-16 19:52:35 +0900 | [diff] [blame] | 147 | } |
Christophe Dervieux | d5dc8e9 | 2021-07-26 14:50:53 +0200 | [diff] [blame] | 148 | # Add quotes around some config that can be several type |
christophe dervieux | ee7e9b5 | 2021-09-16 17:42:17 +0200 | [diff] [blame] | 149 | # like number or percent unit or slideNumber = true or slideNumber = 'c/t' |
| 150 | if ( |
| 151 | option %in% c("slideNumber") || |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 152 | (option %in% c("width", "height") && grepl("%$", value))) { |
Christophe Dervieux | d5dc8e9 | 2021-07-26 14:50:53 +0200 | [diff] [blame] | 153 | value <- paste0("'", value, "'") |
| 154 | } |
| 155 | } |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 156 | args <<- c(args, pandoc_variable_arg(option, value)) |
| 157 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 158 | |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 159 | for (option in names(reveal_options)) { |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 160 | # special handling for nested options |
| 161 | if (option %in% c("chalkboard", "menu")) { |
| 162 | nested_options <- reveal_options[[option]] |
| 163 | for (nested_option in names(nested_options)) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 164 | add_reveal_option( |
| 165 | paste0(option, "-", nested_option), |
| 166 | nested_options[[nested_option]] |
| 167 | ) |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | # standard top-level options |
| 171 | else { |
| 172 | add_reveal_option(option, reveal_options[[option]]) |
| 173 | } |
JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 174 | } |
| 175 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 176 | |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 177 | # reveal plugins |
| 178 | if (is.character(reveal_plugins)) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 179 | |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 180 | # validate that we need to use self_contained for plugins |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 181 | if (self_contained) { |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 182 | stop("Using reveal_plugins requires self_contained: false") |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 183 | } |
| 184 | |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 185 | # validate specified plugins are supported |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 186 | supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu") |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 187 | invalid_plugins <- setdiff(reveal_plugins, supported_plugins) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 188 | if (length(invalid_plugins) > 0) { |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 189 | stop("The following plugin(s) are not supported: ", |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 190 | paste(invalid_plugins, collapse = ", "), |
| 191 | call. = FALSE |
| 192 | ) |
| 193 | } |
| 194 | |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 195 | # add plugins |
| 196 | sapply(reveal_plugins, function(plugin) { |
| 197 | args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin), "1")) |
JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 198 | if (plugin %in% c("chalkboard", "menu")) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 199 | extra_dependencies <<- append( |
| 200 | extra_dependencies, |
| 201 | list(rmarkdown::html_dependency_font_awesome()) |
| 202 | ) |
JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 203 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 204 | }) |
JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 205 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 206 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 207 | # content includes |
| 208 | args <- c(args, includes_to_pandoc_args(includes)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 209 | |
JJ Allaire | fad5523 | 2015-10-19 07:47:26 -0400 | [diff] [blame] | 210 | # additional css |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 211 | for (css_file in css) { |
JJ Allaire | fad5523 | 2015-10-19 07:47:26 -0400 | [diff] [blame] | 212 | args <- c(args, "--css", pandoc_path_arg(css_file)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 213 | } |
| 214 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 215 | # pre-processor for arguments that may depend on the name of the |
| 216 | # the input file (e.g. ones that need to copy supporting files) |
| 217 | pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, |
| 218 | output_dir) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 219 | |
JJ Allaire | e60feb2 | 2016-01-30 18:28:47 -0500 | [diff] [blame] | 220 | # we don't work with runtime shiny |
| 221 | if (identical(runtime, "shiny")) { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 222 | stop("revealjs_presentation is not compatible with runtime 'shiny'", |
| 223 | call. = FALSE |
| 224 | ) |
JJ Allaire | e60feb2 | 2016-01-30 18:28:47 -0500 | [diff] [blame] | 225 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 226 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 227 | # use files_dir as lib_dir if not explicitly specified |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 228 | if (is.null(lib_dir)) { |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 229 | lib_dir <- files_dir |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 230 | } |
| 231 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 232 | # extra args |
| 233 | args <- c() |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 234 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 235 | # reveal.js |
JJ Allaire | 01541a2 | 2017-02-10 10:32:28 -0500 | [diff] [blame] | 236 | revealjs_path <- system.file("reveal.js-3.3.0.1", package = "revealjs") |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 237 | if (!self_contained || identical(.Platform$OS.type, "windows")) { |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 238 | revealjs_path <- relative_to( |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 239 | output_dir, render_supporting_files(revealjs_path, lib_dir) |
| 240 | ) |
| 241 | } else { |
JJ Allaire | eea3bca | 2016-07-13 12:42:01 -0400 | [diff] [blame] | 242 | revealjs_path <- pandoc_path_arg(revealjs_path) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 243 | } |
christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 244 | args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path)) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 245 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 246 | # highlight |
| 247 | args <- c(args, pandoc_highlight_args(highlight, default = "pygments")) |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 248 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 249 | # return additional args |
| 250 | args |
| 251 | } |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 252 | |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 253 | # return format |
| 254 | output_format( |
| 255 | knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md), |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 256 | pandoc = pandoc_options( |
| 257 | to = "revealjs", |
| 258 | from = rmarkdown_format(paste0( |
| 259 | md_extensions, |
| 260 | ifelse(fig_caption, "", "-implicit_figures") |
| 261 | )), |
| 262 | args = args |
| 263 | ), |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 264 | keep_md = keep_md, |
| 265 | clean_supporting = self_contained, |
| 266 | pre_processor = pre_processor, |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 267 | base_format = html_document_base( |
| 268 | smart = smart, lib_dir = lib_dir, |
| 269 | self_contained = self_contained, |
| 270 | mathjax = mathjax, |
| 271 | pandoc_args = pandoc_args, |
| 272 | extra_dependencies = extra_dependencies, |
| 273 | ... |
| 274 | ) |
| 275 | ) |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | revealjs_themes <- function() { |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 279 | c( |
| 280 | "default", |
JJ Allaire | 6da1bb6 | 2016-01-30 14:28:39 -0500 | [diff] [blame] | 281 | "dark", |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 282 | "simple", |
| 283 | "sky", |
| 284 | "beige", |
| 285 | "serif", |
| 286 | "solarized", |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 287 | "blood", |
| 288 | "moon", |
junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 289 | "night", |
| 290 | "black", |
| 291 | "league", |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 292 | "white" |
| 293 | ) |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
| 297 | revealjs_transitions <- function() { |
junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 298 | c( |
| 299 | "default", |
| 300 | "none", |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 301 | "fade", |
junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 302 | "slide", |
| 303 | "convex", |
| 304 | "concave", |
| 305 | "zoom" |
christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 306 | ) |
JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 307 | } |