blob: 75d6c23006169d85ceaecfc67c575ad1180e46d2 [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#' ```
Marc Kupietz6b65c032026-08-25 09:43:28 +030034#' to create notes only viewable in presentation mode. Notes placed before
35#' the first heading are attached to the title slide.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020036#'
Marc Kupietz88799182026-08-24 09:22:33 +030037#' On mobile browsers (touch devices), a button next to the fullscreen
38#' toggle overlays the current slide with its speaker notes (plus the slide
39#' title and, if present, the planned time from a timing comment), which is
40#' useful for practicing a talk on a phone or tablet. It follows along as
41#' you change slides and only appears if the deck contains notes at all.
42#'
Marc Kupietzb066e742026-08-23 09:57:06 +030043#' ## Slide timing
44#'
45#' Speaker time can be planned per slide and per speaker by adding a comment
46#' with a speaker code and the expected duration (in `MM:SS`, `HH:MM:SS`, or
47#' plain seconds format) anywhere inside a slide:
48#'
49#' ```markdown
50#' ## My slide title
51#'
52#' Some content
53#'
54#' <!-- MK 00:30 -->
55#' ```
56#'
57#' This means Marc Kupietz will need 30 seconds for that slide. For talks
58#' presented by a single speaker, the speaker code can be omitted:
Marc Kupietz6b65c032026-08-25 09:43:28 +030059#' `<!-- 00:30 -->`. Comments placed before the first heading are applied to
60#' the title slide.
Marc Kupietzb066e742026-08-23 09:57:06 +030061#'
62#' Typically you start from a known total time budget and adjust the
63#' individual slides to it. You can set this budget yourself with the
64#' reveal.js `totalTime` option (in seconds):
65#'
66#' ```yaml
67#' output:
68#' revealjs.ids::revealjs_presentation:
69#' reveal_options:
70#' totalTime: 3600 # one hour
71#' ```
72#'
73#' During rendering, comments are converted into `data-timing` attributes on
74#' the slides' `<section>` elements (several speakers per slide are summed
75#' up), and the calculated grand total is passed to reveal.js as the
76#' `totalTime` config value. This activates the pacing timer in the
77#' [speaker view](https://revealjs.com/speaker-view/), which shows how you
78#' are doing relative to your plan. A summary of the total time per speaker
79#' is printed during rendering. If the document sets `totalTime` or
80#' `defaultTiming` itself (via `reveal_options`), those take precedence.
81#'
82#' The function [slide_timing()] computes these totals directly from an
83#' `.Rmd` source file without rendering it.
84#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020085#' ### Search
86#'
87#' When opt-in, it is possible to show a search box when pressing `CTRL + SHIFT +
88#' F`. It will seach in the whole presentation, and highlight matched words. The
89#' matches will also be highlighted in overview mode (pressing ESC to see all
90#' slides in one scrollable view)
91#'
92#' ## Menu
93#'
94#' A slideout menu plugin for Reveal.js to quickly jump to any slide by title.
95#'
96#' Version `r version <- readLines(revealjs_lib_path("plugin", "menu", "VERSION"))` is
97#' currently used and documentation for configurations can be found at
98#' [denehyg/reveal.js-menu](https://github.com/denehyg/reveal.js-menu/blob/`r version`/README.md)
99#'
100#' ### Known limitations
101#'
102#' Some configurations cannot be modified in the current template:
103#'
104#' * `loadIcons: false` the fontawesome icons are loaded by \pkg{rmarkdown}
105#' when this plugin is used
106#' * `custom: false`
107#' * `themes: false`
108#' * `transitions: false`
109
110#' ## Chalkboard
111#'
112#' A plugin adding a chalkboard and slide annotation
113#'
114#' Version `r version <- readLines(revealjs_lib_path("plugin", "chalkboard", "VERSION"))` is
115#' currently used and documentation for configurations can be found at
116#' [rajgoel/reveal.js-plugins](https://github.com/rajgoel/reveal.js-plugins/tree/`r version`/4.1.5/chalkboard)
117#'
118#' By default, chalkboard and annotations modes will be accessible using keyboard
119#' shortcuts, respectively, pressing B, or pressing C.
120#' In addition, buttons on the bottom left can be added by using the following
121#'
122#' ```yaml
123#' reveal_plugins:
124#' - chalkboard
125#' reveal_options:
126#' chalkboard:
127#' toggleNotesButton: true
128#' toggleChalkboardButton: true
129#' ```
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300130#' ## Bibliography and citations
131#'
132#' Documents with a `bibliography:` in their YAML header are formatted with
133#' the bundled IDS citation style (`ids.csl`, based on the style developed
134#' for ICLC-10 2023 in Mannheim) by default. To use a different style,
135#' specify it as usual with `csl:` in the YAML header.
136#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400137#' @inheritParams rmarkdown::beamer_presentation
138#' @inheritParams rmarkdown::pdf_document
139#' @inheritParams rmarkdown::html_document
christophe dervieuxf9bae672021-09-21 16:20:24 +0200140#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200141#' @param center `TRUE` to vertically center content on slides
christophe dervieuxf9bae672021-09-21 16:20:24 +0200142#' @param slide_level Level of heading to denote individual slides. If
christophe dervieuxd26add32021-09-23 16:55:00 +0200143#' `slide_level` is 2 (the default), a two-dimensional layout will be
christophe dervieuxf9bae672021-09-21 16:20:24 +0200144#' produced, with level 1 headers building horizontally and level 2 headers
145#' building vertically. It is not recommended that you use deeper nesting of
JJ Allaire4c178052016-01-30 19:35:39 -0500146#' section levels with reveal.js.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200147#' @param theme Visual theme (`r knitr::combine_words(setdiff(revealjs_themes(), "default"), before = '"', and = " or ")`)
148#' @param transition Slide transition (
149#' `r (trans <- knitr::combine_words(setdiff(revealjs_transitions(), "default"), before = '"', and = " or "))`
150#' )
151#' @param background_transition Slide background-transition (
152#' `r trans`
153#' )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200154#' @param reveal_options Additional options to specify for reveal.js (see
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200155#' <https://revealjs.com/config/> for details). Options for plugins can also
156#' be passed, using plugin name as first level key (e.g `list(slideNumber =
157#' FALSE, menu = list(number = TRUE))`).
JJ Allaire35c0b492017-02-10 09:30:24 -0500158#' @param reveal_plugins Reveal plugins to include. Available plugins include
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200159#' "notes", "search", "zoom", "chalkboard", and "menu". Defaults to
160#' `c("notes", "search", "menu", "zoom")`; pass `NULL` to render without
161#' any plugins. Note that `self_contained` must be set to `FALSE` in order
162#' to use Reveal plugins.
christophe dervieuxf9bae672021-09-21 16:20:24 +0200163#' @param template Pandoc template to use for rendering. Pass "default" to use
christophe dervieuxd26add32021-09-23 16:55:00 +0200164#' the rmarkdown package default template; pass `NULL` to use pandoc's
christophe dervieuxf9bae672021-09-21 16:20:24 +0200165#' built-in template; pass a path to use a custom template that you've
166#' created. Note that if you don't use the "default" template then some
christophe dervieuxd26add32021-09-23 16:55:00 +0200167#' features of `revealjs_presentation` won't be available (see the
JJ Allaire4c178052016-01-30 19:35:39 -0500168#' Templates section below for more details).
JJ Allaire35c0b492017-02-10 09:30:24 -0500169#' @param extra_dependencies Additional function arguments to pass to the base R
170#' Markdown HTML output formatter [rmarkdown::html_document_base()].
JJ Allaire8d1c2f42016-01-30 14:56:45 -0500171#' @param ... Ignored
christophe dervieuxf9bae672021-09-21 16:20:24 +0200172#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200173#' @return R Markdown output format to pass to [rmarkdown::render()]
christophe dervieuxf9bae672021-09-21 16:20:24 +0200174#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400175#' @examples
176#' \dontrun{
christophe dervieuxf9bae672021-09-21 16:20:24 +0200177#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400178#' library(rmarkdown)
Marc Kupietze195cea2026-08-17 13:17:33 +0200179#' library(revealjs.ids)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200180#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400181#' # simple invocation
182#' render("pres.Rmd", revealjs_presentation())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200183#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400184#' # specify an option for incremental rendering
185#' render("pres.Rmd", revealjs_presentation(incremental = TRUE))
186#' }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200187#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400188#' @export
189revealjs_presentation <- function(incremental = FALSE,
190 center = FALSE,
JJ Allaire4c178052016-01-30 19:35:39 -0500191 slide_level = 2,
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200192 toc = FALSE,
193 toc_depth = 3,
JJ Allaire2ec40242014-09-15 09:18:39 -0400194 fig_width = 8,
195 fig_height = 6,
196 fig_retina = if (!fig_caption) 2,
197 fig_caption = FALSE,
Marc Kupietzf8d5ff12023-10-09 18:58:09 +0200198 self_contained = FALSE,
199 theme = "ids",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200200 transition = "convex",
201 background_transition = "fade",
JJ Allaire37f45b72016-01-30 18:17:45 -0500202 reveal_options = NULL,
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200203 reveal_plugins = c("notes", "search", "menu", "zoom"),
JJ Allaire2ec40242014-09-15 09:18:39 -0400204 highlight = "default",
205 mathjax = "default",
206 template = "default",
JJ Allairefad55232015-10-19 07:47:26 -0400207 css = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400208 includes = NULL,
209 keep_md = FALSE,
210 lib_dir = NULL,
211 pandoc_args = NULL,
JJ Allaire375805c2016-11-15 08:56:43 -0500212 extra_dependencies = NULL,
Atsushi Yasumoto0bf44442020-02-15 00:08:30 +0900213 md_extensions = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400214 ...) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200215
JJ Allaire2ec40242014-09-15 09:18:39 -0400216 # base pandoc options for all reveal.js output
217 args <- c()
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200218
219 # table of contents
220 args <- c(args, pandoc_toc_args(toc, toc_depth))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200221
JJ Allaire2ec40242014-09-15 09:18:39 -0400222 # template path and assets
JJ Allairea8c414b2016-01-30 14:36:53 -0500223 if (identical(template, "default")) {
christophe dervieux92fa4692021-09-21 16:15:17 +0200224 default_template <- reveal_resources("default.html")
JJ Allairea8c414b2016-01-30 14:36:53 -0500225 args <- c(args, "--template", pandoc_path_arg(default_template))
226 } else if (!is.null(template)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400227 args <- c(args, "--template", pandoc_path_arg(template))
JJ Allairea8c414b2016-01-30 14:36:53 -0500228 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200229
JJ Allaire2ec40242014-09-15 09:18:39 -0400230 # incremental
christophe dervieuxf9bae672021-09-21 16:20:24 +0200231 if (incremental) args <- c(args, "--incremental")
232
JJ Allaire2ec40242014-09-15 09:18:39 -0400233 # centering
JJ Allaire40fec332016-01-30 16:54:51 -0500234 args <- c(args, pandoc_variable_arg("center", jsbool(center)))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200235
JJ Allaire4c178052016-01-30 19:35:39 -0500236 # slide level
JJ Allairec58a6c42016-03-30 23:45:21 -0400237 args <- c(args, "--slide-level", as.character(slide_level))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200238
JJ Allaire2ec40242014-09-15 09:18:39 -0400239 # theme
240 theme <- match.arg(theme, revealjs_themes())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200241 if (identical(theme, "default")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400242 theme <- "simple"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200243 } else if (identical(theme, "dark")) {
JJ Allaire6da1bb62016-01-30 14:28:39 -0500244 theme <- "black"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200245 }
246 if (theme %in% c("blood", "moon", "night", "black")) {
christophe dervieux062940d2021-09-21 16:26:14 +0200247 args <- c(args, pandoc_variable_arg("theme-dark"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200248 }
christophe dervieux1ebd5132021-09-22 08:47:21 +0200249 args <- c(args, pandoc_variable_arg("theme", theme))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200250
Marc Kupietz7c8f7de2023-10-07 11:42:29 +0200251 if (theme == "ids") {
252 args <- c(args, pandoc_variable_arg("theme-ids"))
253 fig_height = 7
254 fig_width = 12
255 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200256
JJ Allaire2ec40242014-09-15 09:18:39 -0400257 # transition
Marc Kupietz9d96fda2026-08-11 16:55:13 +0200258 if (missing(transition) && identical(theme, "ids")) {
259 # IDS theme: slide the slides in instead of rotating them (reveal.js'
260 # own default, convex), unless the user explicitly asked for something
261 # else. The formal default has to stay "convex" for the other themes.
262 transition <- "slide"
263 }
JJ Allaire2ec40242014-09-15 09:18:39 -0400264 transition <- match.arg(transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200265 if (identical(transition, "default")) {
266 # revealjs default is convex
267 transition <- "convex"
268 }
christophe dervieux062940d2021-09-21 16:26:14 +0200269 args <- c(args, pandoc_variable_arg("transition", transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200270
junkkad55cff02015-03-15 22:27:03 +0100271 # background_transition
272 background_transition <- match.arg(background_transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200273 if (identical(background_transition, "default")) {
274 # revealjs default is fade
275 background_transition <- "fade"
276 }
christophe dervieux062940d2021-09-21 16:26:14 +0200277 args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200278
JJ Allaire4ae486f2016-03-23 06:08:42 -0400279 # use history
280 args <- c(args, pandoc_variable_arg("history", "true"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200281
Marc Kupietza0f8f682026-08-08 14:13:11 +0200282 # The IDS corporate design puts the orange bar flush against the top left
283 # corner of the slide. reveal.js defaults to margin = 0.04, i.e. it keeps 4%
284 # of the display empty around the content, which would leave a white border
285 # above and to the left of the bar. Default to 0 instead, unless the document
286 # asks for a margin of its own via reveal_options.
287 if (!is.list(reveal_options) || is.null(reveal_options[["margin"]])) {
288 args <- c(args, pandoc_variable_arg("margin", "0"))
289 }
290
JJ Allaire37f45b72016-01-30 18:17:45 -0500291 # additional reveal options
292 if (is.list(reveal_options)) {
JJ Allaire375805c2016-11-15 08:56:43 -0500293 for (option in names(reveal_options)) {
JJ Allaire064552c2017-02-10 10:28:41 -0500294 # special handling for nested options
295 if (option %in% c("chalkboard", "menu")) {
296 nested_options <- reveal_options[[option]]
297 for (nested_option in names(nested_options)) {
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200298 args <- c(args,
299 process_reveal_option(
300 paste0(option, "-", nested_option),
301 nested_options[[nested_option]]
302 )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200303 )
JJ Allaire375805c2016-11-15 08:56:43 -0500304 }
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200305 } else {
306 # standard top-level options
307 args <- c(args, process_reveal_option(option, reveal_options[[option]]))
JJ Allaire375805c2016-11-15 08:56:43 -0500308 }
JJ Allaire37f45b72016-01-30 18:17:45 -0500309 }
310 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200311
JJ Allaire82a8dee2016-07-12 10:25:36 -0400312 # reveal plugins
313 if (is.character(reveal_plugins)) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200314
JJ Allaire82a8dee2016-07-12 10:25:36 -0400315 # validate that we need to use self_contained for plugins
christophe dervieuxf9bae672021-09-21 16:20:24 +0200316 if (self_contained) {
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200317 if (missing(reveal_plugins)) {
318 # the default plugin set collided with an explicitly requested
319 # self_contained render -- drop the defaults instead of failing
320 warning("Reveal plugins require self_contained: false -- ",
321 "rendering without the default plugins.",
322 call. = FALSE
323 )
324 reveal_plugins <- character(0)
325 } else {
326 stop("Using reveal_plugins requires self_contained: false")
327 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200328 }
329
JJ Allaire82a8dee2016-07-12 10:25:36 -0400330 # validate specified plugins are supported
JJ Allaire064552c2017-02-10 10:28:41 -0500331 supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu")
JJ Allaire82a8dee2016-07-12 10:25:36 -0400332 invalid_plugins <- setdiff(reveal_plugins, supported_plugins)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200333 if (length(invalid_plugins) > 0) {
JJ Allaire82a8dee2016-07-12 10:25:36 -0400334 stop("The following plugin(s) are not supported: ",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200335 paste(invalid_plugins, collapse = ", "),
336 call. = FALSE
337 )
338 }
339
JJ Allaire82a8dee2016-07-12 10:25:36 -0400340 # add plugins
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200341 if ("chalkboard" %in% reveal_plugins) {
342 # chalkboard require customcontrols so we add it to activate in the template
343 reveal_plugins <- c(reveal_plugins, "customcontrols")
344 }
JJ Allaire82a8dee2016-07-12 10:25:36 -0400345 sapply(reveal_plugins, function(plugin) {
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200346 args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin)))
347 if (plugin %in% c("customcontrols", "menu")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200348 extra_dependencies <<- append(
349 extra_dependencies,
350 list(rmarkdown::html_dependency_font_awesome())
351 )
JJ Allaire375805c2016-11-15 08:56:43 -0500352 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200353 })
JJ Allaire82a8dee2016-07-12 10:25:36 -0400354 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200355
JJ Allaire2ec40242014-09-15 09:18:39 -0400356 # content includes
357 args <- c(args, includes_to_pandoc_args(includes))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200358
JJ Allairefad55232015-10-19 07:47:26 -0400359 # additional css
christophe dervieuxf9bae672021-09-21 16:20:24 +0200360 for (css_file in css) {
JJ Allairefad55232015-10-19 07:47:26 -0400361 args <- c(args, "--css", pandoc_path_arg(css_file))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200362 }
363
JJ Allaire2ec40242014-09-15 09:18:39 -0400364 # pre-processor for arguments that may depend on the name of the
365 # the input file (e.g. ones that need to copy supporting files)
366 pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
367 output_dir) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200368
JJ Allairee60feb22016-01-30 18:28:47 -0500369 # we don't work with runtime shiny
370 if (identical(runtime, "shiny")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200371 stop("revealjs_presentation is not compatible with runtime 'shiny'",
372 call. = FALSE
373 )
JJ Allairee60feb22016-01-30 18:28:47 -0500374 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200375
JJ Allaire2ec40242014-09-15 09:18:39 -0400376 # use files_dir as lib_dir if not explicitly specified
christophe dervieuxf9bae672021-09-21 16:20:24 +0200377 if (is.null(lib_dir)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400378 lib_dir <- files_dir
christophe dervieuxf9bae672021-09-21 16:20:24 +0200379 }
380
JJ Allaire2ec40242014-09-15 09:18:39 -0400381 # extra args
382 args <- c()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200383
JJ Allaire2ec40242014-09-15 09:18:39 -0400384 # reveal.js
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200385 revealjs_path <- revealjs_lib_path()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200386 if (!self_contained || identical(.Platform$OS.type, "windows")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400387 revealjs_path <- relative_to(
christophe dervieuxf9bae672021-09-21 16:20:24 +0200388 output_dir, render_supporting_files(revealjs_path, lib_dir)
389 )
390 } else {
JJ Allaireeea3bca2016-07-13 12:42:01 -0400391 revealjs_path <- pandoc_path_arg(revealjs_path)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200392 }
christophe dervieux062940d2021-09-21 16:26:14 +0200393 args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200394
JJ Allaire2ec40242014-09-15 09:18:39 -0400395 # highlight
396 args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200397
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300398 # default to the bundled IDS citation style unless the document
399 # specifies a style of its own
400 if (is.null(metadata$csl)) {
401 args <- c(args, "--csl", pandoc_path_arg(reveal_resources("ids.csl")))
402 }
403
JJ Allaire2ec40242014-09-15 09:18:39 -0400404 # return additional args
405 args
406 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200407
Marc Kupietzb066e742026-08-23 09:57:06 +0300408 # post-processor converting <!-- MK 00:30 --> speaker timing comments into
409 # data-timing attributes on the enclosing sections (activating the pacing
410 # timer of the notes plugin) and reporting per-speaker totals
411 post_processor <- function(metadata, input_file, output_file, clean, verbose) {
412 lines <- readLines(output_file, warn = FALSE, encoding = "UTF-8")
Marc Kupietz6b65c032026-08-25 09:43:28 +0300413 lines <- merge_title_slide_notes(lines)
Marc Kupietzb066e742026-08-23 09:57:06 +0300414 result <- apply_timing_attributes(lines)
415 comments <- attr(result, "comments")
416 if (nrow(comments) > 0) {
417 result <- inject_total_time(result, sum(comments$seconds))
418 writeLines(enc2utf8(result), output_file, useBytes = TRUE)
419 message(timing_report_message(comments))
420 }
421 output_file
422 }
423
JJ Allaire2ec40242014-09-15 09:18:39 -0400424 # return format
425 output_format(
426 knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200427 pandoc = pandoc_options(
428 to = "revealjs",
christophe dervieuxad3a5752021-09-23 10:24:09 +0200429 from = from_rmarkdown(fig_caption, md_extensions),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200430 args = args
431 ),
JJ Allaire2ec40242014-09-15 09:18:39 -0400432 keep_md = keep_md,
433 clean_supporting = self_contained,
434 pre_processor = pre_processor,
Marc Kupietzb066e742026-08-23 09:57:06 +0300435 post_processor = post_processor,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200436 base_format = html_document_base(
christophe dervieux0acc6c92021-09-23 11:18:18 +0200437 lib_dir = lib_dir,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200438 self_contained = self_contained,
439 mathjax = mathjax,
440 pandoc_args = pandoc_args,
441 extra_dependencies = extra_dependencies,
442 ...
443 )
444 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400445}
446
447revealjs_themes <- function() {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200448 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200449 "default", # not used by reveal
Marc Kupietza737b1b2023-10-07 09:32:20 +0200450 "ids",
JJ Allaire2ec40242014-09-15 09:18:39 -0400451 "simple",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200452 "dark", # our alias for black
453 "black",
JJ Allaire2ec40242014-09-15 09:18:39 -0400454 "sky",
455 "beige",
456 "serif",
457 "solarized",
JJ Allaire2ec40242014-09-15 09:18:39 -0400458 "blood",
459 "moon",
junkka77fbf082015-03-15 22:25:47 +0100460 "night",
junkka77fbf082015-03-15 22:25:47 +0100461 "league",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200462 "white"
463 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400464}
465
JJ Allaire2ec40242014-09-15 09:18:39 -0400466revealjs_transitions <- function() {
junkka77fbf082015-03-15 22:25:47 +0100467 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200468 "default", # not used by reveal
469 "convex",
JJ Allaire2ec40242014-09-15 09:18:39 -0400470 "fade",
junkka77fbf082015-03-15 22:25:47 +0100471 "slide",
junkka77fbf082015-03-15 22:25:47 +0100472 "concave",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200473 "zoom",
474 "none"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200475 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400476}