blob: 950b8b846790f7d1ac15adde5244ca86e983394c [file] [log] [blame]
JJ Allaire2ec40242014-09-15 09:18:39 -04001#' Convert to a reveal.js presentation
christophe dervieuxf9bae672021-09-21 16:20:24 +02002#'
JJ Allaire2ec40242014-09-15 09:18:39 -04003#' Format for converting from R Markdown to a reveal.js presentation.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +02004#'
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 dervieuxf9bae672021-09-21 16:20:24 +02009#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020010#' 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#'
Marc Kupietzb066e742026-08-23 09:57:06 +030036#' ## Slide timing
37#'
38#' Speaker time can be planned per slide and per speaker by adding a comment
39#' with a speaker code and the expected duration (in `MM:SS`, `HH:MM:SS`, or
40#' plain seconds format) anywhere inside a slide:
41#'
42#' ```markdown
43#' ## My slide title
44#'
45#' Some content
46#'
47#' <!-- MK 00:30 -->
48#' ```
49#'
50#' This means Marc Kupietz will need 30 seconds for that slide. For talks
51#' presented by a single speaker, the speaker code can be omitted:
52#' `<!-- 00:30 -->`.
53#'
54#' Typically you start from a known total time budget and adjust the
55#' individual slides to it. You can set this budget yourself with the
56#' reveal.js `totalTime` option (in seconds):
57#'
58#' ```yaml
59#' output:
60#' revealjs.ids::revealjs_presentation:
61#' reveal_options:
62#' totalTime: 3600 # one hour
63#' ```
64#'
65#' During rendering, comments are converted into `data-timing` attributes on
66#' the slides' `<section>` elements (several speakers per slide are summed
67#' up), and the calculated grand total is passed to reveal.js as the
68#' `totalTime` config value. This activates the pacing timer in the
69#' [speaker view](https://revealjs.com/speaker-view/), which shows how you
70#' are doing relative to your plan. A summary of the total time per speaker
71#' is printed during rendering. If the document sets `totalTime` or
72#' `defaultTiming` itself (via `reveal_options`), those take precedence.
73#'
74#' The function [slide_timing()] computes these totals directly from an
75#' `.Rmd` source file without rendering it.
76#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020077#' ### Search
78#'
79#' When opt-in, it is possible to show a search box when pressing `CTRL + SHIFT +
80#' F`. It will seach in the whole presentation, and highlight matched words. The
81#' matches will also be highlighted in overview mode (pressing ESC to see all
82#' slides in one scrollable view)
83#'
84#' ## Menu
85#'
86#' A slideout menu plugin for Reveal.js to quickly jump to any slide by title.
87#'
88#' Version `r version <- readLines(revealjs_lib_path("plugin", "menu", "VERSION"))` is
89#' currently used and documentation for configurations can be found at
90#' [denehyg/reveal.js-menu](https://github.com/denehyg/reveal.js-menu/blob/`r version`/README.md)
91#'
92#' ### Known limitations
93#'
94#' Some configurations cannot be modified in the current template:
95#'
96#' * `loadIcons: false` the fontawesome icons are loaded by \pkg{rmarkdown}
97#' when this plugin is used
98#' * `custom: false`
99#' * `themes: false`
100#' * `transitions: false`
101
102#' ## Chalkboard
103#'
104#' A plugin adding a chalkboard and slide annotation
105#'
106#' Version `r version <- readLines(revealjs_lib_path("plugin", "chalkboard", "VERSION"))` is
107#' currently used and documentation for configurations can be found at
108#' [rajgoel/reveal.js-plugins](https://github.com/rajgoel/reveal.js-plugins/tree/`r version`/4.1.5/chalkboard)
109#'
110#' By default, chalkboard and annotations modes will be accessible using keyboard
111#' shortcuts, respectively, pressing B, or pressing C.
112#' In addition, buttons on the bottom left can be added by using the following
113#'
114#' ```yaml
115#' reveal_plugins:
116#' - chalkboard
117#' reveal_options:
118#' chalkboard:
119#' toggleNotesButton: true
120#' toggleChalkboardButton: true
121#' ```
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300122#' ## Bibliography and citations
123#'
124#' Documents with a `bibliography:` in their YAML header are formatted with
125#' the bundled IDS citation style (`ids.csl`, based on the style developed
126#' for ICLC-10 2023 in Mannheim) by default. To use a different style,
127#' specify it as usual with `csl:` in the YAML header.
128#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400129#' @inheritParams rmarkdown::beamer_presentation
130#' @inheritParams rmarkdown::pdf_document
131#' @inheritParams rmarkdown::html_document
christophe dervieuxf9bae672021-09-21 16:20:24 +0200132#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200133#' @param center `TRUE` to vertically center content on slides
christophe dervieuxf9bae672021-09-21 16:20:24 +0200134#' @param slide_level Level of heading to denote individual slides. If
christophe dervieuxd26add32021-09-23 16:55:00 +0200135#' `slide_level` is 2 (the default), a two-dimensional layout will be
christophe dervieuxf9bae672021-09-21 16:20:24 +0200136#' produced, with level 1 headers building horizontally and level 2 headers
137#' building vertically. It is not recommended that you use deeper nesting of
JJ Allaire4c178052016-01-30 19:35:39 -0500138#' section levels with reveal.js.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200139#' @param theme Visual theme (`r knitr::combine_words(setdiff(revealjs_themes(), "default"), before = '"', and = " or ")`)
140#' @param transition Slide transition (
141#' `r (trans <- knitr::combine_words(setdiff(revealjs_transitions(), "default"), before = '"', and = " or "))`
142#' )
143#' @param background_transition Slide background-transition (
144#' `r trans`
145#' )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200146#' @param reveal_options Additional options to specify for reveal.js (see
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200147#' <https://revealjs.com/config/> for details). Options for plugins can also
148#' be passed, using plugin name as first level key (e.g `list(slideNumber =
149#' FALSE, menu = list(number = TRUE))`).
JJ Allaire35c0b492017-02-10 09:30:24 -0500150#' @param reveal_plugins Reveal plugins to include. Available plugins include
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200151#' "notes", "search", "zoom", "chalkboard", and "menu". Defaults to
152#' `c("notes", "search", "menu", "zoom")`; pass `NULL` to render without
153#' any plugins. Note that `self_contained` must be set to `FALSE` in order
154#' to use Reveal plugins.
christophe dervieuxf9bae672021-09-21 16:20:24 +0200155#' @param template Pandoc template to use for rendering. Pass "default" to use
christophe dervieuxd26add32021-09-23 16:55:00 +0200156#' the rmarkdown package default template; pass `NULL` to use pandoc's
christophe dervieuxf9bae672021-09-21 16:20:24 +0200157#' built-in template; pass a path to use a custom template that you've
158#' created. Note that if you don't use the "default" template then some
christophe dervieuxd26add32021-09-23 16:55:00 +0200159#' features of `revealjs_presentation` won't be available (see the
JJ Allaire4c178052016-01-30 19:35:39 -0500160#' Templates section below for more details).
JJ Allaire35c0b492017-02-10 09:30:24 -0500161#' @param extra_dependencies Additional function arguments to pass to the base R
162#' Markdown HTML output formatter [rmarkdown::html_document_base()].
JJ Allaire8d1c2f42016-01-30 14:56:45 -0500163#' @param ... Ignored
christophe dervieuxf9bae672021-09-21 16:20:24 +0200164#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200165#' @return R Markdown output format to pass to [rmarkdown::render()]
christophe dervieuxf9bae672021-09-21 16:20:24 +0200166#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400167#' @examples
168#' \dontrun{
christophe dervieuxf9bae672021-09-21 16:20:24 +0200169#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400170#' library(rmarkdown)
Marc Kupietze195cea2026-08-17 13:17:33 +0200171#' library(revealjs.ids)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200172#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400173#' # simple invocation
174#' render("pres.Rmd", revealjs_presentation())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200175#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400176#' # specify an option for incremental rendering
177#' render("pres.Rmd", revealjs_presentation(incremental = TRUE))
178#' }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200179#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400180#' @export
181revealjs_presentation <- function(incremental = FALSE,
182 center = FALSE,
JJ Allaire4c178052016-01-30 19:35:39 -0500183 slide_level = 2,
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200184 toc = FALSE,
185 toc_depth = 3,
JJ Allaire2ec40242014-09-15 09:18:39 -0400186 fig_width = 8,
187 fig_height = 6,
188 fig_retina = if (!fig_caption) 2,
189 fig_caption = FALSE,
Marc Kupietzf8d5ff12023-10-09 18:58:09 +0200190 self_contained = FALSE,
191 theme = "ids",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200192 transition = "convex",
193 background_transition = "fade",
JJ Allaire37f45b72016-01-30 18:17:45 -0500194 reveal_options = NULL,
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200195 reveal_plugins = c("notes", "search", "menu", "zoom"),
JJ Allaire2ec40242014-09-15 09:18:39 -0400196 highlight = "default",
197 mathjax = "default",
198 template = "default",
JJ Allairefad55232015-10-19 07:47:26 -0400199 css = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400200 includes = NULL,
201 keep_md = FALSE,
202 lib_dir = NULL,
203 pandoc_args = NULL,
JJ Allaire375805c2016-11-15 08:56:43 -0500204 extra_dependencies = NULL,
Atsushi Yasumoto0bf44442020-02-15 00:08:30 +0900205 md_extensions = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400206 ...) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200207
JJ Allaire2ec40242014-09-15 09:18:39 -0400208 # base pandoc options for all reveal.js output
209 args <- c()
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200210
211 # table of contents
212 args <- c(args, pandoc_toc_args(toc, toc_depth))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200213
JJ Allaire2ec40242014-09-15 09:18:39 -0400214 # template path and assets
JJ Allairea8c414b2016-01-30 14:36:53 -0500215 if (identical(template, "default")) {
christophe dervieux92fa4692021-09-21 16:15:17 +0200216 default_template <- reveal_resources("default.html")
JJ Allairea8c414b2016-01-30 14:36:53 -0500217 args <- c(args, "--template", pandoc_path_arg(default_template))
218 } else if (!is.null(template)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400219 args <- c(args, "--template", pandoc_path_arg(template))
JJ Allairea8c414b2016-01-30 14:36:53 -0500220 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200221
JJ Allaire2ec40242014-09-15 09:18:39 -0400222 # incremental
christophe dervieuxf9bae672021-09-21 16:20:24 +0200223 if (incremental) args <- c(args, "--incremental")
224
JJ Allaire2ec40242014-09-15 09:18:39 -0400225 # centering
JJ Allaire40fec332016-01-30 16:54:51 -0500226 args <- c(args, pandoc_variable_arg("center", jsbool(center)))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200227
JJ Allaire4c178052016-01-30 19:35:39 -0500228 # slide level
JJ Allairec58a6c42016-03-30 23:45:21 -0400229 args <- c(args, "--slide-level", as.character(slide_level))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200230
JJ Allaire2ec40242014-09-15 09:18:39 -0400231 # theme
232 theme <- match.arg(theme, revealjs_themes())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200233 if (identical(theme, "default")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400234 theme <- "simple"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200235 } else if (identical(theme, "dark")) {
JJ Allaire6da1bb62016-01-30 14:28:39 -0500236 theme <- "black"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200237 }
238 if (theme %in% c("blood", "moon", "night", "black")) {
christophe dervieux062940d2021-09-21 16:26:14 +0200239 args <- c(args, pandoc_variable_arg("theme-dark"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200240 }
christophe dervieux1ebd5132021-09-22 08:47:21 +0200241 args <- c(args, pandoc_variable_arg("theme", theme))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200242
Marc Kupietz7c8f7de2023-10-07 11:42:29 +0200243 if (theme == "ids") {
244 args <- c(args, pandoc_variable_arg("theme-ids"))
245 fig_height = 7
246 fig_width = 12
247 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200248
JJ Allaire2ec40242014-09-15 09:18:39 -0400249 # transition
Marc Kupietz9d96fda2026-08-11 16:55:13 +0200250 if (missing(transition) && identical(theme, "ids")) {
251 # IDS theme: slide the slides in instead of rotating them (reveal.js'
252 # own default, convex), unless the user explicitly asked for something
253 # else. The formal default has to stay "convex" for the other themes.
254 transition <- "slide"
255 }
JJ Allaire2ec40242014-09-15 09:18:39 -0400256 transition <- match.arg(transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200257 if (identical(transition, "default")) {
258 # revealjs default is convex
259 transition <- "convex"
260 }
christophe dervieux062940d2021-09-21 16:26:14 +0200261 args <- c(args, pandoc_variable_arg("transition", transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200262
junkkad55cff02015-03-15 22:27:03 +0100263 # background_transition
264 background_transition <- match.arg(background_transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200265 if (identical(background_transition, "default")) {
266 # revealjs default is fade
267 background_transition <- "fade"
268 }
christophe dervieux062940d2021-09-21 16:26:14 +0200269 args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200270
JJ Allaire4ae486f2016-03-23 06:08:42 -0400271 # use history
272 args <- c(args, pandoc_variable_arg("history", "true"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200273
Marc Kupietza0f8f682026-08-08 14:13:11 +0200274 # The IDS corporate design puts the orange bar flush against the top left
275 # corner of the slide. reveal.js defaults to margin = 0.04, i.e. it keeps 4%
276 # of the display empty around the content, which would leave a white border
277 # above and to the left of the bar. Default to 0 instead, unless the document
278 # asks for a margin of its own via reveal_options.
279 if (!is.list(reveal_options) || is.null(reveal_options[["margin"]])) {
280 args <- c(args, pandoc_variable_arg("margin", "0"))
281 }
282
JJ Allaire37f45b72016-01-30 18:17:45 -0500283 # additional reveal options
284 if (is.list(reveal_options)) {
JJ Allaire375805c2016-11-15 08:56:43 -0500285 for (option in names(reveal_options)) {
JJ Allaire064552c2017-02-10 10:28:41 -0500286 # special handling for nested options
287 if (option %in% c("chalkboard", "menu")) {
288 nested_options <- reveal_options[[option]]
289 for (nested_option in names(nested_options)) {
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200290 args <- c(args,
291 process_reveal_option(
292 paste0(option, "-", nested_option),
293 nested_options[[nested_option]]
294 )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200295 )
JJ Allaire375805c2016-11-15 08:56:43 -0500296 }
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200297 } else {
298 # standard top-level options
299 args <- c(args, process_reveal_option(option, reveal_options[[option]]))
JJ Allaire375805c2016-11-15 08:56:43 -0500300 }
JJ Allaire37f45b72016-01-30 18:17:45 -0500301 }
302 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200303
JJ Allaire82a8dee2016-07-12 10:25:36 -0400304 # reveal plugins
305 if (is.character(reveal_plugins)) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200306
JJ Allaire82a8dee2016-07-12 10:25:36 -0400307 # validate that we need to use self_contained for plugins
christophe dervieuxf9bae672021-09-21 16:20:24 +0200308 if (self_contained) {
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200309 if (missing(reveal_plugins)) {
310 # the default plugin set collided with an explicitly requested
311 # self_contained render -- drop the defaults instead of failing
312 warning("Reveal plugins require self_contained: false -- ",
313 "rendering without the default plugins.",
314 call. = FALSE
315 )
316 reveal_plugins <- character(0)
317 } else {
318 stop("Using reveal_plugins requires self_contained: false")
319 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200320 }
321
JJ Allaire82a8dee2016-07-12 10:25:36 -0400322 # validate specified plugins are supported
JJ Allaire064552c2017-02-10 10:28:41 -0500323 supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu")
JJ Allaire82a8dee2016-07-12 10:25:36 -0400324 invalid_plugins <- setdiff(reveal_plugins, supported_plugins)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200325 if (length(invalid_plugins) > 0) {
JJ Allaire82a8dee2016-07-12 10:25:36 -0400326 stop("The following plugin(s) are not supported: ",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200327 paste(invalid_plugins, collapse = ", "),
328 call. = FALSE
329 )
330 }
331
JJ Allaire82a8dee2016-07-12 10:25:36 -0400332 # add plugins
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200333 if ("chalkboard" %in% reveal_plugins) {
334 # chalkboard require customcontrols so we add it to activate in the template
335 reveal_plugins <- c(reveal_plugins, "customcontrols")
336 }
JJ Allaire82a8dee2016-07-12 10:25:36 -0400337 sapply(reveal_plugins, function(plugin) {
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200338 args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin)))
339 if (plugin %in% c("customcontrols", "menu")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200340 extra_dependencies <<- append(
341 extra_dependencies,
342 list(rmarkdown::html_dependency_font_awesome())
343 )
JJ Allaire375805c2016-11-15 08:56:43 -0500344 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200345 })
JJ Allaire82a8dee2016-07-12 10:25:36 -0400346 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200347
JJ Allaire2ec40242014-09-15 09:18:39 -0400348 # content includes
349 args <- c(args, includes_to_pandoc_args(includes))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200350
JJ Allairefad55232015-10-19 07:47:26 -0400351 # additional css
christophe dervieuxf9bae672021-09-21 16:20:24 +0200352 for (css_file in css) {
JJ Allairefad55232015-10-19 07:47:26 -0400353 args <- c(args, "--css", pandoc_path_arg(css_file))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200354 }
355
JJ Allaire2ec40242014-09-15 09:18:39 -0400356 # pre-processor for arguments that may depend on the name of the
357 # the input file (e.g. ones that need to copy supporting files)
358 pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
359 output_dir) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200360
JJ Allairee60feb22016-01-30 18:28:47 -0500361 # we don't work with runtime shiny
362 if (identical(runtime, "shiny")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200363 stop("revealjs_presentation is not compatible with runtime 'shiny'",
364 call. = FALSE
365 )
JJ Allairee60feb22016-01-30 18:28:47 -0500366 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200367
JJ Allaire2ec40242014-09-15 09:18:39 -0400368 # use files_dir as lib_dir if not explicitly specified
christophe dervieuxf9bae672021-09-21 16:20:24 +0200369 if (is.null(lib_dir)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400370 lib_dir <- files_dir
christophe dervieuxf9bae672021-09-21 16:20:24 +0200371 }
372
JJ Allaire2ec40242014-09-15 09:18:39 -0400373 # extra args
374 args <- c()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200375
JJ Allaire2ec40242014-09-15 09:18:39 -0400376 # reveal.js
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200377 revealjs_path <- revealjs_lib_path()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200378 if (!self_contained || identical(.Platform$OS.type, "windows")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400379 revealjs_path <- relative_to(
christophe dervieuxf9bae672021-09-21 16:20:24 +0200380 output_dir, render_supporting_files(revealjs_path, lib_dir)
381 )
382 } else {
JJ Allaireeea3bca2016-07-13 12:42:01 -0400383 revealjs_path <- pandoc_path_arg(revealjs_path)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200384 }
christophe dervieux062940d2021-09-21 16:26:14 +0200385 args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200386
JJ Allaire2ec40242014-09-15 09:18:39 -0400387 # highlight
388 args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200389
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300390 # default to the bundled IDS citation style unless the document
391 # specifies a style of its own
392 if (is.null(metadata$csl)) {
393 args <- c(args, "--csl", pandoc_path_arg(reveal_resources("ids.csl")))
394 }
395
JJ Allaire2ec40242014-09-15 09:18:39 -0400396 # return additional args
397 args
398 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200399
Marc Kupietzb066e742026-08-23 09:57:06 +0300400 # post-processor converting <!-- MK 00:30 --> speaker timing comments into
401 # data-timing attributes on the enclosing sections (activating the pacing
402 # timer of the notes plugin) and reporting per-speaker totals
403 post_processor <- function(metadata, input_file, output_file, clean, verbose) {
404 lines <- readLines(output_file, warn = FALSE, encoding = "UTF-8")
405 result <- apply_timing_attributes(lines)
406 comments <- attr(result, "comments")
407 if (nrow(comments) > 0) {
408 result <- inject_total_time(result, sum(comments$seconds))
409 writeLines(enc2utf8(result), output_file, useBytes = TRUE)
410 message(timing_report_message(comments))
411 }
412 output_file
413 }
414
JJ Allaire2ec40242014-09-15 09:18:39 -0400415 # return format
416 output_format(
417 knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200418 pandoc = pandoc_options(
419 to = "revealjs",
christophe dervieuxad3a5752021-09-23 10:24:09 +0200420 from = from_rmarkdown(fig_caption, md_extensions),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200421 args = args
422 ),
JJ Allaire2ec40242014-09-15 09:18:39 -0400423 keep_md = keep_md,
424 clean_supporting = self_contained,
425 pre_processor = pre_processor,
Marc Kupietzb066e742026-08-23 09:57:06 +0300426 post_processor = post_processor,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200427 base_format = html_document_base(
christophe dervieux0acc6c92021-09-23 11:18:18 +0200428 lib_dir = lib_dir,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200429 self_contained = self_contained,
430 mathjax = mathjax,
431 pandoc_args = pandoc_args,
432 extra_dependencies = extra_dependencies,
433 ...
434 )
435 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400436}
437
438revealjs_themes <- function() {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200439 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200440 "default", # not used by reveal
Marc Kupietza737b1b2023-10-07 09:32:20 +0200441 "ids",
JJ Allaire2ec40242014-09-15 09:18:39 -0400442 "simple",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200443 "dark", # our alias for black
444 "black",
JJ Allaire2ec40242014-09-15 09:18:39 -0400445 "sky",
446 "beige",
447 "serif",
448 "solarized",
JJ Allaire2ec40242014-09-15 09:18:39 -0400449 "blood",
450 "moon",
junkka77fbf082015-03-15 22:25:47 +0100451 "night",
junkka77fbf082015-03-15 22:25:47 +0100452 "league",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200453 "white"
454 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400455}
456
JJ Allaire2ec40242014-09-15 09:18:39 -0400457revealjs_transitions <- function() {
junkka77fbf082015-03-15 22:25:47 +0100458 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200459 "default", # not used by reveal
460 "convex",
JJ Allaire2ec40242014-09-15 09:18:39 -0400461 "fade",
junkka77fbf082015-03-15 22:25:47 +0100462 "slide",
junkka77fbf082015-03-15 22:25:47 +0100463 "concave",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200464 "zoom",
465 "none"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200466 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400467}