| 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 | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 4 | #' |
| 5 | #' In reveal.js presentations you can use level 1 or level 2 headers for slides. |
| 6 | #' If you use a mix of level 1 and level 2 headers then a two-dimensional layout |
| 7 | #' will be produced, with level 1 headers building horizontally and level 2 |
| 8 | #' headers building vertically. |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 9 | #' |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 10 | #' For additional documentation on using revealjs presentations see |
| 11 | #' <https://github.com/rstudio/revealjs> |
| 12 | #' |
| 13 | #' # About plugins |
| 14 | #' |
| 15 | #' ## Built-in plugins with reveal.js |
| 16 | #' |
| 17 | #' ### Zoom |
| 18 | #' |
| 19 | #' When activated, ALT + Click can be used to zoom on a slide. |
| 20 | #' |
| 21 | #' ### Notes |
| 22 | #' |
| 23 | #' Show a [speaker view](https://revealjs.com/speaker-view/) in a separated |
| 24 | #' window. This speaker view contains a timer, current slide, next slide, and |
| 25 | #' speaker notes. It also duplicate the window to have presentation mode |
| 26 | #' synchronized with main presentation. |
| 27 | #' |
| 28 | #' Use |
| 29 | #' ```markdown |
| 30 | #' ::: notes |
| 31 | #' Content of speaker notes |
| 32 | #' ::: |
| 33 | #' ``` |
| 34 | #' to create notes only viewable in presentation mode. |
| 35 | #' |
| 36 | #' ### Search |
| 37 | #' |
| 38 | #' When opt-in, it is possible to show a search box when pressing `CTRL + SHIFT + |
| 39 | #' F`. It will seach in the whole presentation, and highlight matched words. The |
| 40 | #' matches will also be highlighted in overview mode (pressing ESC to see all |
| 41 | #' slides in one scrollable view) |
| 42 | #' |
| 43 | #' ## Menu |
| 44 | #' |
| 45 | #' A slideout menu plugin for Reveal.js to quickly jump to any slide by title. |
| 46 | #' |
| 47 | #' Version `r version <- readLines(revealjs_lib_path("plugin", "menu", "VERSION"))` is |
| 48 | #' currently used and documentation for configurations can be found at |
| 49 | #' [denehyg/reveal.js-menu](https://github.com/denehyg/reveal.js-menu/blob/`r version`/README.md) |
| 50 | #' |
| 51 | #' ### Known limitations |
| 52 | #' |
| 53 | #' Some configurations cannot be modified in the current template: |
| 54 | #' |
| 55 | #' * `loadIcons: false` the fontawesome icons are loaded by \pkg{rmarkdown} |
| 56 | #' when this plugin is used |
| 57 | #' * `custom: false` |
| 58 | #' * `themes: false` |
| 59 | #' * `transitions: false` |
| 60 | |
| 61 | #' ## Chalkboard |
| 62 | #' |
| 63 | #' A plugin adding a chalkboard and slide annotation |
| 64 | #' |
| 65 | #' Version `r version <- readLines(revealjs_lib_path("plugin", "chalkboard", "VERSION"))` is |
| 66 | #' currently used and documentation for configurations can be found at |
| 67 | #' [rajgoel/reveal.js-plugins](https://github.com/rajgoel/reveal.js-plugins/tree/`r version`/4.1.5/chalkboard) |
| 68 | #' |
| 69 | #' By default, chalkboard and annotations modes will be accessible using keyboard |
| 70 | #' shortcuts, respectively, pressing B, or pressing C. |
| 71 | #' In addition, buttons on the bottom left can be added by using the following |
| 72 | #' |
| 73 | #' ```yaml |
| 74 | #' reveal_plugins: |
| 75 | #' - chalkboard |
| 76 | #' reveal_options: |
| 77 | #' chalkboard: |
| 78 | #' toggleNotesButton: true |
| 79 | #' toggleChalkboardButton: true |
| 80 | #' ``` |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 81 | #' @inheritParams rmarkdown::beamer_presentation |
| 82 | #' @inheritParams rmarkdown::pdf_document |
| 83 | #' @inheritParams rmarkdown::html_document |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 84 | #' |
| christophe dervieux | d26add3 | 2021-09-23 16:55:00 +0200 | [diff] [blame] | 85 | #' @param center `TRUE` to vertically center content on slides |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 86 | #' @param slide_level Level of heading to denote individual slides. If |
| christophe dervieux | d26add3 | 2021-09-23 16:55:00 +0200 | [diff] [blame] | 87 | #' `slide_level` is 2 (the default), a two-dimensional layout will be |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 88 | #' produced, with level 1 headers building horizontally and level 2 headers |
| 89 | #' building vertically. It is not recommended that you use deeper nesting of |
| JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 90 | #' section levels with reveal.js. |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 91 | #' @param theme Visual theme (`r knitr::combine_words(setdiff(revealjs_themes(), "default"), before = '"', and = " or ")`) |
| 92 | #' @param transition Slide transition ( |
| 93 | #' `r (trans <- knitr::combine_words(setdiff(revealjs_transitions(), "default"), before = '"', and = " or "))` |
| 94 | #' ) |
| 95 | #' @param background_transition Slide background-transition ( |
| 96 | #' `r trans` |
| 97 | #' ) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 98 | #' @param reveal_options Additional options to specify for reveal.js (see |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 99 | #' <https://revealjs.com/config/> for details). Options for plugins can also |
| 100 | #' be passed, using plugin name as first level key (e.g `list(slideNumber = |
| 101 | #' FALSE, menu = list(number = TRUE))`). |
| JJ Allaire | 35c0b49 | 2017-02-10 09:30:24 -0500 | [diff] [blame] | 102 | #' @param reveal_plugins Reveal plugins to include. Available plugins include |
| Marc Kupietz | 03dbc5d | 2026-08-21 15:44:25 +0200 | [diff] [blame^] | 103 | #' "notes", "search", "zoom", "chalkboard", and "menu". Defaults to |
| 104 | #' `c("notes", "search", "menu", "zoom")`; pass `NULL` to render without |
| 105 | #' any plugins. Note that `self_contained` must be set to `FALSE` in order |
| 106 | #' to use Reveal plugins. |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 107 | #' @param template Pandoc template to use for rendering. Pass "default" to use |
| christophe dervieux | d26add3 | 2021-09-23 16:55:00 +0200 | [diff] [blame] | 108 | #' the rmarkdown package default template; pass `NULL` to use pandoc's |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 109 | #' built-in template; pass a path to use a custom template that you've |
| 110 | #' created. Note that if you don't use the "default" template then some |
| christophe dervieux | d26add3 | 2021-09-23 16:55:00 +0200 | [diff] [blame] | 111 | #' features of `revealjs_presentation` won't be available (see the |
| JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 112 | #' Templates section below for more details). |
| JJ Allaire | 35c0b49 | 2017-02-10 09:30:24 -0500 | [diff] [blame] | 113 | #' @param extra_dependencies Additional function arguments to pass to the base R |
| 114 | #' Markdown HTML output formatter [rmarkdown::html_document_base()]. |
| JJ Allaire | 8d1c2f4 | 2016-01-30 14:56:45 -0500 | [diff] [blame] | 115 | #' @param ... Ignored |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 116 | #' |
| christophe dervieux | d26add3 | 2021-09-23 16:55:00 +0200 | [diff] [blame] | 117 | #' @return R Markdown output format to pass to [rmarkdown::render()] |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 118 | #' |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 119 | #' @examples |
| 120 | #' \dontrun{ |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 121 | #' |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 122 | #' library(rmarkdown) |
| Marc Kupietz | e195cea | 2026-08-17 13:17:33 +0200 | [diff] [blame] | 123 | #' library(revealjs.ids) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 124 | #' |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 125 | #' # simple invocation |
| 126 | #' render("pres.Rmd", revealjs_presentation()) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 127 | #' |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 128 | #' # specify an option for incremental rendering |
| 129 | #' render("pres.Rmd", revealjs_presentation(incremental = TRUE)) |
| 130 | #' } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 131 | #' |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 132 | #' @export |
| 133 | revealjs_presentation <- function(incremental = FALSE, |
| 134 | center = FALSE, |
| JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 135 | slide_level = 2, |
| Christophe Dervieux | aa008e4 | 2021-09-23 16:52:37 +0200 | [diff] [blame] | 136 | toc = FALSE, |
| 137 | toc_depth = 3, |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 138 | fig_width = 8, |
| 139 | fig_height = 6, |
| 140 | fig_retina = if (!fig_caption) 2, |
| 141 | fig_caption = FALSE, |
| Marc Kupietz | f8d5ff1 | 2023-10-09 18:58:09 +0200 | [diff] [blame] | 142 | self_contained = FALSE, |
| 143 | theme = "ids", |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 144 | transition = "convex", |
| 145 | background_transition = "fade", |
| JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 146 | reveal_options = NULL, |
| Marc Kupietz | 03dbc5d | 2026-08-21 15:44:25 +0200 | [diff] [blame^] | 147 | reveal_plugins = c("notes", "search", "menu", "zoom"), |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 148 | highlight = "default", |
| 149 | mathjax = "default", |
| 150 | template = "default", |
| JJ Allaire | fad5523 | 2015-10-19 07:47:26 -0400 | [diff] [blame] | 151 | css = NULL, |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 152 | includes = NULL, |
| 153 | keep_md = FALSE, |
| 154 | lib_dir = NULL, |
| 155 | pandoc_args = NULL, |
| JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 156 | extra_dependencies = NULL, |
| Atsushi Yasumoto | 0bf4444 | 2020-02-15 00:08:30 +0900 | [diff] [blame] | 157 | md_extensions = NULL, |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 158 | ...) { |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 159 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 160 | # base pandoc options for all reveal.js output |
| 161 | args <- c() |
| Christophe Dervieux | aa008e4 | 2021-09-23 16:52:37 +0200 | [diff] [blame] | 162 | |
| 163 | # table of contents |
| 164 | args <- c(args, pandoc_toc_args(toc, toc_depth)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 165 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 166 | # template path and assets |
| JJ Allaire | a8c414b | 2016-01-30 14:36:53 -0500 | [diff] [blame] | 167 | if (identical(template, "default")) { |
| christophe dervieux | 92fa469 | 2021-09-21 16:15:17 +0200 | [diff] [blame] | 168 | default_template <- reveal_resources("default.html") |
| JJ Allaire | a8c414b | 2016-01-30 14:36:53 -0500 | [diff] [blame] | 169 | args <- c(args, "--template", pandoc_path_arg(default_template)) |
| 170 | } else if (!is.null(template)) { |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 171 | args <- c(args, "--template", pandoc_path_arg(template)) |
| JJ Allaire | a8c414b | 2016-01-30 14:36:53 -0500 | [diff] [blame] | 172 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 173 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 174 | # incremental |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 175 | if (incremental) args <- c(args, "--incremental") |
| 176 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 177 | # centering |
| JJ Allaire | 40fec33 | 2016-01-30 16:54:51 -0500 | [diff] [blame] | 178 | args <- c(args, pandoc_variable_arg("center", jsbool(center))) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 179 | |
| JJ Allaire | 4c17805 | 2016-01-30 19:35:39 -0500 | [diff] [blame] | 180 | # slide level |
| JJ Allaire | c58a6c4 | 2016-03-30 23:45:21 -0400 | [diff] [blame] | 181 | args <- c(args, "--slide-level", as.character(slide_level)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 182 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 183 | # theme |
| 184 | theme <- match.arg(theme, revealjs_themes()) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 185 | if (identical(theme, "default")) { |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 186 | theme <- "simple" |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 187 | } else if (identical(theme, "dark")) { |
| JJ Allaire | 6da1bb6 | 2016-01-30 14:28:39 -0500 | [diff] [blame] | 188 | theme <- "black" |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 189 | } |
| 190 | if (theme %in% c("blood", "moon", "night", "black")) { |
| christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 191 | args <- c(args, pandoc_variable_arg("theme-dark")) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 192 | } |
| christophe dervieux | 1ebd513 | 2021-09-22 08:47:21 +0200 | [diff] [blame] | 193 | args <- c(args, pandoc_variable_arg("theme", theme)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 194 | |
| Marc Kupietz | 7c8f7de | 2023-10-07 11:42:29 +0200 | [diff] [blame] | 195 | if (theme == "ids") { |
| 196 | args <- c(args, pandoc_variable_arg("theme-ids")) |
| 197 | fig_height = 7 |
| 198 | fig_width = 12 |
| 199 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 200 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 201 | # transition |
| Marc Kupietz | 9d96fda | 2026-08-11 16:55:13 +0200 | [diff] [blame] | 202 | if (missing(transition) && identical(theme, "ids")) { |
| 203 | # IDS theme: slide the slides in instead of rotating them (reveal.js' |
| 204 | # own default, convex), unless the user explicitly asked for something |
| 205 | # else. The formal default has to stay "convex" for the other themes. |
| 206 | transition <- "slide" |
| 207 | } |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 208 | transition <- match.arg(transition, revealjs_transitions()) |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 209 | if (identical(transition, "default")) { |
| 210 | # revealjs default is convex |
| 211 | transition <- "convex" |
| 212 | } |
| christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 213 | args <- c(args, pandoc_variable_arg("transition", transition)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 214 | |
| junkka | d55cff0 | 2015-03-15 22:27:03 +0100 | [diff] [blame] | 215 | # background_transition |
| 216 | background_transition <- match.arg(background_transition, revealjs_transitions()) |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 217 | if (identical(background_transition, "default")) { |
| 218 | # revealjs default is fade |
| 219 | background_transition <- "fade" |
| 220 | } |
| christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 221 | args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 222 | |
| JJ Allaire | 4ae486f | 2016-03-23 06:08:42 -0400 | [diff] [blame] | 223 | # use history |
| 224 | args <- c(args, pandoc_variable_arg("history", "true")) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 225 | |
| Marc Kupietz | a0f8f68 | 2026-08-08 14:13:11 +0200 | [diff] [blame] | 226 | # The IDS corporate design puts the orange bar flush against the top left |
| 227 | # corner of the slide. reveal.js defaults to margin = 0.04, i.e. it keeps 4% |
| 228 | # of the display empty around the content, which would leave a white border |
| 229 | # above and to the left of the bar. Default to 0 instead, unless the document |
| 230 | # asks for a margin of its own via reveal_options. |
| 231 | if (!is.list(reveal_options) || is.null(reveal_options[["margin"]])) { |
| 232 | args <- c(args, pandoc_variable_arg("margin", "0")) |
| 233 | } |
| 234 | |
| JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 235 | # additional reveal options |
| 236 | if (is.list(reveal_options)) { |
| JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 237 | for (option in names(reveal_options)) { |
| JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 238 | # special handling for nested options |
| 239 | if (option %in% c("chalkboard", "menu")) { |
| 240 | nested_options <- reveal_options[[option]] |
| 241 | for (nested_option in names(nested_options)) { |
| Christophe Dervieux | 2f01dc9 | 2021-09-22 09:37:18 +0200 | [diff] [blame] | 242 | args <- c(args, |
| 243 | process_reveal_option( |
| 244 | paste0(option, "-", nested_option), |
| 245 | nested_options[[nested_option]] |
| 246 | ) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 247 | ) |
| JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 248 | } |
| Christophe Dervieux | 2f01dc9 | 2021-09-22 09:37:18 +0200 | [diff] [blame] | 249 | } else { |
| 250 | # standard top-level options |
| 251 | args <- c(args, process_reveal_option(option, reveal_options[[option]])) |
| JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 252 | } |
| JJ Allaire | 37f45b7 | 2016-01-30 18:17:45 -0500 | [diff] [blame] | 253 | } |
| 254 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 255 | |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 256 | # reveal plugins |
| 257 | if (is.character(reveal_plugins)) { |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 258 | |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 259 | # validate that we need to use self_contained for plugins |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 260 | if (self_contained) { |
| Marc Kupietz | 03dbc5d | 2026-08-21 15:44:25 +0200 | [diff] [blame^] | 261 | if (missing(reveal_plugins)) { |
| 262 | # the default plugin set collided with an explicitly requested |
| 263 | # self_contained render -- drop the defaults instead of failing |
| 264 | warning("Reveal plugins require self_contained: false -- ", |
| 265 | "rendering without the default plugins.", |
| 266 | call. = FALSE |
| 267 | ) |
| 268 | reveal_plugins <- character(0) |
| 269 | } else { |
| 270 | stop("Using reveal_plugins requires self_contained: false") |
| 271 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 274 | # validate specified plugins are supported |
| JJ Allaire | 064552c | 2017-02-10 10:28:41 -0500 | [diff] [blame] | 275 | supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu") |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 276 | invalid_plugins <- setdiff(reveal_plugins, supported_plugins) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 277 | if (length(invalid_plugins) > 0) { |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 278 | stop("The following plugin(s) are not supported: ", |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 279 | paste(invalid_plugins, collapse = ", "), |
| 280 | call. = FALSE |
| 281 | ) |
| 282 | } |
| 283 | |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 284 | # add plugins |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 285 | if ("chalkboard" %in% reveal_plugins) { |
| 286 | # chalkboard require customcontrols so we add it to activate in the template |
| 287 | reveal_plugins <- c(reveal_plugins, "customcontrols") |
| 288 | } |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 289 | sapply(reveal_plugins, function(plugin) { |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 290 | args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin))) |
| 291 | if (plugin %in% c("customcontrols", "menu")) { |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 292 | extra_dependencies <<- append( |
| 293 | extra_dependencies, |
| 294 | list(rmarkdown::html_dependency_font_awesome()) |
| 295 | ) |
| JJ Allaire | 375805c | 2016-11-15 08:56:43 -0500 | [diff] [blame] | 296 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 297 | }) |
| JJ Allaire | 82a8dee | 2016-07-12 10:25:36 -0400 | [diff] [blame] | 298 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 299 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 300 | # content includes |
| 301 | args <- c(args, includes_to_pandoc_args(includes)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 302 | |
| JJ Allaire | fad5523 | 2015-10-19 07:47:26 -0400 | [diff] [blame] | 303 | # additional css |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 304 | for (css_file in css) { |
| JJ Allaire | fad5523 | 2015-10-19 07:47:26 -0400 | [diff] [blame] | 305 | args <- c(args, "--css", pandoc_path_arg(css_file)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 308 | # pre-processor for arguments that may depend on the name of the |
| 309 | # the input file (e.g. ones that need to copy supporting files) |
| 310 | pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir, |
| 311 | output_dir) { |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 312 | |
| JJ Allaire | e60feb2 | 2016-01-30 18:28:47 -0500 | [diff] [blame] | 313 | # we don't work with runtime shiny |
| 314 | if (identical(runtime, "shiny")) { |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 315 | stop("revealjs_presentation is not compatible with runtime 'shiny'", |
| 316 | call. = FALSE |
| 317 | ) |
| JJ Allaire | e60feb2 | 2016-01-30 18:28:47 -0500 | [diff] [blame] | 318 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 319 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 320 | # use files_dir as lib_dir if not explicitly specified |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 321 | if (is.null(lib_dir)) { |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 322 | lib_dir <- files_dir |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 323 | } |
| 324 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 325 | # extra args |
| 326 | args <- c() |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 327 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 328 | # reveal.js |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 329 | revealjs_path <- revealjs_lib_path() |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 330 | if (!self_contained || identical(.Platform$OS.type, "windows")) { |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 331 | revealjs_path <- relative_to( |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 332 | output_dir, render_supporting_files(revealjs_path, lib_dir) |
| 333 | ) |
| 334 | } else { |
| JJ Allaire | eea3bca | 2016-07-13 12:42:01 -0400 | [diff] [blame] | 335 | revealjs_path <- pandoc_path_arg(revealjs_path) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 336 | } |
| christophe dervieux | 062940d | 2021-09-21 16:26:14 +0200 | [diff] [blame] | 337 | args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path)) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 338 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 339 | # highlight |
| 340 | args <- c(args, pandoc_highlight_args(highlight, default = "pygments")) |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 341 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 342 | # return additional args |
| 343 | args |
| 344 | } |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 345 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 346 | # return format |
| 347 | output_format( |
| 348 | knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md), |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 349 | pandoc = pandoc_options( |
| 350 | to = "revealjs", |
| christophe dervieux | ad3a575 | 2021-09-23 10:24:09 +0200 | [diff] [blame] | 351 | from = from_rmarkdown(fig_caption, md_extensions), |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 352 | args = args |
| 353 | ), |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 354 | keep_md = keep_md, |
| 355 | clean_supporting = self_contained, |
| 356 | pre_processor = pre_processor, |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 357 | base_format = html_document_base( |
| christophe dervieux | 0acc6c9 | 2021-09-23 11:18:18 +0200 | [diff] [blame] | 358 | lib_dir = lib_dir, |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 359 | self_contained = self_contained, |
| 360 | mathjax = mathjax, |
| 361 | pandoc_args = pandoc_args, |
| 362 | extra_dependencies = extra_dependencies, |
| 363 | ... |
| 364 | ) |
| 365 | ) |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | revealjs_themes <- function() { |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 369 | c( |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 370 | "default", # not used by reveal |
| Marc Kupietz | a737b1b | 2023-10-07 09:32:20 +0200 | [diff] [blame] | 371 | "ids", |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 372 | "simple", |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 373 | "dark", # our alias for black |
| 374 | "black", |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 375 | "sky", |
| 376 | "beige", |
| 377 | "serif", |
| 378 | "solarized", |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 379 | "blood", |
| 380 | "moon", |
| junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 381 | "night", |
| junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 382 | "league", |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 383 | "white" |
| 384 | ) |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 385 | } |
| 386 | |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 387 | revealjs_transitions <- function() { |
| junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 388 | c( |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 389 | "default", # not used by reveal |
| 390 | "convex", |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 391 | "fade", |
| junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 392 | "slide", |
| junkka | 77fbf08 | 2015-03-15 22:25:47 +0100 | [diff] [blame] | 393 | "concave", |
| Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 394 | "zoom", |
| 395 | "none" |
| christophe dervieux | f9bae67 | 2021-09-21 16:20:24 +0200 | [diff] [blame] | 396 | ) |
| JJ Allaire | 2ec4024 | 2014-09-15 09:18:39 -0400 | [diff] [blame] | 397 | } |