blob: e73ede905a0373c0d98923e12b82c172268a54f0 [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 Kupietzeaaa2b42026-08-26 09:41:27 +030043#' Pressing `r` toggles a transcript view: a single scrollable page
44#' containing every slide's content and speaker notes. Text-to-speech
45#' ("read aloud") browser extensions cannot walk a reveal.js deck, since
46#' hidden slides are not part of the visible page text -- the transcript
47#' gives them something they can read from start to finish.
48#'
Marc Kupietzb066e742026-08-23 09:57:06 +030049#' ## Slide timing
50#'
51#' Speaker time can be planned per slide and per speaker by adding a comment
52#' with a speaker code and the expected duration (in `MM:SS`, `HH:MM:SS`, or
53#' plain seconds format) anywhere inside a slide:
54#'
55#' ```markdown
56#' ## My slide title
57#'
58#' Some content
59#'
60#' <!-- MK 00:30 -->
61#' ```
62#'
63#' This means Marc Kupietz will need 30 seconds for that slide. For talks
64#' presented by a single speaker, the speaker code can be omitted:
Marc Kupietz6b65c032026-08-25 09:43:28 +030065#' `<!-- 00:30 -->`. Comments placed before the first heading are applied to
66#' the title slide.
Marc Kupietzb066e742026-08-23 09:57:06 +030067#'
68#' Typically you start from a known total time budget and adjust the
69#' individual slides to it. You can set this budget yourself with the
70#' reveal.js `totalTime` option (in seconds):
71#'
72#' ```yaml
73#' output:
74#' revealjs.ids::revealjs_presentation:
75#' reveal_options:
76#' totalTime: 3600 # one hour
77#' ```
78#'
79#' During rendering, comments are converted into `data-timing` attributes on
80#' the slides' `<section>` elements (several speakers per slide are summed
81#' up), and the calculated grand total is passed to reveal.js as the
82#' `totalTime` config value. This activates the pacing timer in the
83#' [speaker view](https://revealjs.com/speaker-view/), which shows how you
84#' are doing relative to your plan. A summary of the total time per speaker
85#' is printed during rendering. If the document sets `totalTime` or
86#' `defaultTiming` itself (via `reveal_options`), those take precedence.
87#'
88#' The function [slide_timing()] computes these totals directly from an
89#' `.Rmd` source file without rendering it.
90#'
Marc Kupietz4eb03202026-08-25 10:58:10 +030091#' ## Overview slides
92#'
93#' Like in the original Google Docs slide workflow, a slide titled
94#' "Overview" or "Überblick" is automatically turned into a table of
95#' contents: its body content is replaced at presentation time with a
96#' clickable list of all `#` chapter headings. Adding
97#' `{data-overview-subheadings=true}` to the heading also includes the
98#' `##` sub-headings below their chapters, laid out in two columns.
99#' References and appendix chapters (References/Literatur/
100#' Literaturverzeichnis/Appendix/Anhang) are left out, together with
101#' their sub-slides.
102#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200103#' ### Search
104#'
105#' When opt-in, it is possible to show a search box when pressing `CTRL + SHIFT +
106#' F`. It will seach in the whole presentation, and highlight matched words. The
107#' matches will also be highlighted in overview mode (pressing ESC to see all
108#' slides in one scrollable view)
109#'
110#' ## Menu
111#'
112#' A slideout menu plugin for Reveal.js to quickly jump to any slide by title.
113#'
114#' Version `r version <- readLines(revealjs_lib_path("plugin", "menu", "VERSION"))` is
115#' currently used and documentation for configurations can be found at
116#' [denehyg/reveal.js-menu](https://github.com/denehyg/reveal.js-menu/blob/`r version`/README.md)
117#'
118#' ### Known limitations
119#'
120#' Some configurations cannot be modified in the current template:
121#'
122#' * `loadIcons: false` the fontawesome icons are loaded by \pkg{rmarkdown}
123#' when this plugin is used
124#' * `custom: false`
125#' * `themes: false`
126#' * `transitions: false`
127
128#' ## Chalkboard
129#'
130#' A plugin adding a chalkboard and slide annotation
131#'
132#' Version `r version <- readLines(revealjs_lib_path("plugin", "chalkboard", "VERSION"))` is
133#' currently used and documentation for configurations can be found at
134#' [rajgoel/reveal.js-plugins](https://github.com/rajgoel/reveal.js-plugins/tree/`r version`/4.1.5/chalkboard)
135#'
136#' By default, chalkboard and annotations modes will be accessible using keyboard
137#' shortcuts, respectively, pressing B, or pressing C.
138#' In addition, buttons on the bottom left can be added by using the following
139#'
140#' ```yaml
141#' reveal_plugins:
142#' - chalkboard
143#' reveal_options:
144#' chalkboard:
145#' toggleNotesButton: true
146#' toggleChalkboardButton: true
147#' ```
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300148#' ## Bibliography and citations
149#'
150#' Documents with a `bibliography:` in their YAML header are formatted with
151#' the bundled IDS citation style (`ids.csl`, based on the style developed
152#' for ICLC-10 2023 in Mannheim) by default. To use a different style,
153#' specify it as usual with `csl:` in the YAML header.
154#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400155#' @inheritParams rmarkdown::beamer_presentation
156#' @inheritParams rmarkdown::pdf_document
157#' @inheritParams rmarkdown::html_document
christophe dervieuxf9bae672021-09-21 16:20:24 +0200158#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200159#' @param center `TRUE` to vertically center content on slides
christophe dervieuxf9bae672021-09-21 16:20:24 +0200160#' @param slide_level Level of heading to denote individual slides. If
christophe dervieuxd26add32021-09-23 16:55:00 +0200161#' `slide_level` is 2 (the default), a two-dimensional layout will be
christophe dervieuxf9bae672021-09-21 16:20:24 +0200162#' produced, with level 1 headers building horizontally and level 2 headers
163#' building vertically. It is not recommended that you use deeper nesting of
JJ Allaire4c178052016-01-30 19:35:39 -0500164#' section levels with reveal.js.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200165#' @param theme Visual theme (`r knitr::combine_words(setdiff(revealjs_themes(), "default"), before = '"', and = " or ")`)
166#' @param transition Slide transition (
167#' `r (trans <- knitr::combine_words(setdiff(revealjs_transitions(), "default"), before = '"', and = " or "))`
168#' )
169#' @param background_transition Slide background-transition (
170#' `r trans`
171#' )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200172#' @param reveal_options Additional options to specify for reveal.js (see
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200173#' <https://revealjs.com/config/> for details). Options for plugins can also
174#' be passed, using plugin name as first level key (e.g `list(slideNumber =
175#' FALSE, menu = list(number = TRUE))`).
JJ Allaire35c0b492017-02-10 09:30:24 -0500176#' @param reveal_plugins Reveal plugins to include. Available plugins include
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200177#' "notes", "search", "zoom", "chalkboard", and "menu". Defaults to
178#' `c("notes", "search", "menu", "zoom")`; pass `NULL` to render without
179#' any plugins. Note that `self_contained` must be set to `FALSE` in order
180#' to use Reveal plugins.
christophe dervieuxf9bae672021-09-21 16:20:24 +0200181#' @param template Pandoc template to use for rendering. Pass "default" to use
christophe dervieuxd26add32021-09-23 16:55:00 +0200182#' the rmarkdown package default template; pass `NULL` to use pandoc's
christophe dervieuxf9bae672021-09-21 16:20:24 +0200183#' built-in template; pass a path to use a custom template that you've
184#' created. Note that if you don't use the "default" template then some
christophe dervieuxd26add32021-09-23 16:55:00 +0200185#' features of `revealjs_presentation` won't be available (see the
JJ Allaire4c178052016-01-30 19:35:39 -0500186#' Templates section below for more details).
JJ Allaire35c0b492017-02-10 09:30:24 -0500187#' @param extra_dependencies Additional function arguments to pass to the base R
188#' Markdown HTML output formatter [rmarkdown::html_document_base()].
JJ Allaire8d1c2f42016-01-30 14:56:45 -0500189#' @param ... Ignored
christophe dervieuxf9bae672021-09-21 16:20:24 +0200190#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200191#' @return R Markdown output format to pass to [rmarkdown::render()]
christophe dervieuxf9bae672021-09-21 16:20:24 +0200192#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400193#' @examples
194#' \dontrun{
christophe dervieuxf9bae672021-09-21 16:20:24 +0200195#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400196#' library(rmarkdown)
Marc Kupietze195cea2026-08-17 13:17:33 +0200197#' library(revealjs.ids)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200198#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400199#' # simple invocation
200#' render("pres.Rmd", revealjs_presentation())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200201#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400202#' # specify an option for incremental rendering
203#' render("pres.Rmd", revealjs_presentation(incremental = TRUE))
204#' }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200205#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400206#' @export
207revealjs_presentation <- function(incremental = FALSE,
208 center = FALSE,
JJ Allaire4c178052016-01-30 19:35:39 -0500209 slide_level = 2,
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200210 toc = FALSE,
211 toc_depth = 3,
JJ Allaire2ec40242014-09-15 09:18:39 -0400212 fig_width = 8,
213 fig_height = 6,
214 fig_retina = if (!fig_caption) 2,
215 fig_caption = FALSE,
Marc Kupietzf8d5ff12023-10-09 18:58:09 +0200216 self_contained = FALSE,
217 theme = "ids",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200218 transition = "convex",
219 background_transition = "fade",
JJ Allaire37f45b72016-01-30 18:17:45 -0500220 reveal_options = NULL,
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200221 reveal_plugins = c("notes", "search", "menu", "zoom"),
JJ Allaire2ec40242014-09-15 09:18:39 -0400222 highlight = "default",
223 mathjax = "default",
224 template = "default",
JJ Allairefad55232015-10-19 07:47:26 -0400225 css = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400226 includes = NULL,
227 keep_md = FALSE,
228 lib_dir = NULL,
229 pandoc_args = NULL,
JJ Allaire375805c2016-11-15 08:56:43 -0500230 extra_dependencies = NULL,
Atsushi Yasumoto0bf44442020-02-15 00:08:30 +0900231 md_extensions = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400232 ...) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200233
JJ Allaire2ec40242014-09-15 09:18:39 -0400234 # base pandoc options for all reveal.js output
235 args <- c()
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200236
237 # table of contents
238 args <- c(args, pandoc_toc_args(toc, toc_depth))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200239
JJ Allaire2ec40242014-09-15 09:18:39 -0400240 # template path and assets
JJ Allairea8c414b2016-01-30 14:36:53 -0500241 if (identical(template, "default")) {
christophe dervieux92fa4692021-09-21 16:15:17 +0200242 default_template <- reveal_resources("default.html")
JJ Allairea8c414b2016-01-30 14:36:53 -0500243 args <- c(args, "--template", pandoc_path_arg(default_template))
244 } else if (!is.null(template)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400245 args <- c(args, "--template", pandoc_path_arg(template))
JJ Allairea8c414b2016-01-30 14:36:53 -0500246 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200247
JJ Allaire2ec40242014-09-15 09:18:39 -0400248 # incremental
christophe dervieuxf9bae672021-09-21 16:20:24 +0200249 if (incremental) args <- c(args, "--incremental")
250
JJ Allaire2ec40242014-09-15 09:18:39 -0400251 # centering
JJ Allaire40fec332016-01-30 16:54:51 -0500252 args <- c(args, pandoc_variable_arg("center", jsbool(center)))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200253
JJ Allaire4c178052016-01-30 19:35:39 -0500254 # slide level
JJ Allairec58a6c42016-03-30 23:45:21 -0400255 args <- c(args, "--slide-level", as.character(slide_level))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200256
JJ Allaire2ec40242014-09-15 09:18:39 -0400257 # theme
258 theme <- match.arg(theme, revealjs_themes())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200259 if (identical(theme, "default")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400260 theme <- "simple"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200261 } else if (identical(theme, "dark")) {
JJ Allaire6da1bb62016-01-30 14:28:39 -0500262 theme <- "black"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200263 }
264 if (theme %in% c("blood", "moon", "night", "black")) {
christophe dervieux062940d2021-09-21 16:26:14 +0200265 args <- c(args, pandoc_variable_arg("theme-dark"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200266 }
christophe dervieux1ebd5132021-09-22 08:47:21 +0200267 args <- c(args, pandoc_variable_arg("theme", theme))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200268
Marc Kupietz7c8f7de2023-10-07 11:42:29 +0200269 if (theme == "ids") {
270 args <- c(args, pandoc_variable_arg("theme-ids"))
271 fig_height = 7
272 fig_width = 12
273 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200274
JJ Allaire2ec40242014-09-15 09:18:39 -0400275 # transition
Marc Kupietz9d96fda2026-08-11 16:55:13 +0200276 if (missing(transition) && identical(theme, "ids")) {
277 # IDS theme: slide the slides in instead of rotating them (reveal.js'
278 # own default, convex), unless the user explicitly asked for something
279 # else. The formal default has to stay "convex" for the other themes.
280 transition <- "slide"
281 }
JJ Allaire2ec40242014-09-15 09:18:39 -0400282 transition <- match.arg(transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200283 if (identical(transition, "default")) {
284 # revealjs default is convex
285 transition <- "convex"
286 }
christophe dervieux062940d2021-09-21 16:26:14 +0200287 args <- c(args, pandoc_variable_arg("transition", transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200288
junkkad55cff02015-03-15 22:27:03 +0100289 # background_transition
290 background_transition <- match.arg(background_transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200291 if (identical(background_transition, "default")) {
292 # revealjs default is fade
293 background_transition <- "fade"
294 }
christophe dervieux062940d2021-09-21 16:26:14 +0200295 args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200296
JJ Allaire4ae486f2016-03-23 06:08:42 -0400297 # use history
298 args <- c(args, pandoc_variable_arg("history", "true"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200299
Marc Kupietza0f8f682026-08-08 14:13:11 +0200300 # The IDS corporate design puts the orange bar flush against the top left
301 # corner of the slide. reveal.js defaults to margin = 0.04, i.e. it keeps 4%
302 # of the display empty around the content, which would leave a white border
303 # above and to the left of the bar. Default to 0 instead, unless the document
304 # asks for a margin of its own via reveal_options.
305 if (!is.list(reveal_options) || is.null(reveal_options[["margin"]])) {
306 args <- c(args, pandoc_variable_arg("margin", "0"))
307 }
308
JJ Allaire37f45b72016-01-30 18:17:45 -0500309 # additional reveal options
310 if (is.list(reveal_options)) {
JJ Allaire375805c2016-11-15 08:56:43 -0500311 for (option in names(reveal_options)) {
JJ Allaire064552c2017-02-10 10:28:41 -0500312 # special handling for nested options
313 if (option %in% c("chalkboard", "menu")) {
314 nested_options <- reveal_options[[option]]
315 for (nested_option in names(nested_options)) {
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200316 args <- c(args,
317 process_reveal_option(
318 paste0(option, "-", nested_option),
319 nested_options[[nested_option]]
320 )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200321 )
JJ Allaire375805c2016-11-15 08:56:43 -0500322 }
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200323 } else {
324 # standard top-level options
325 args <- c(args, process_reveal_option(option, reveal_options[[option]]))
JJ Allaire375805c2016-11-15 08:56:43 -0500326 }
JJ Allaire37f45b72016-01-30 18:17:45 -0500327 }
328 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200329
JJ Allaire82a8dee2016-07-12 10:25:36 -0400330 # reveal plugins
331 if (is.character(reveal_plugins)) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200332
JJ Allaire82a8dee2016-07-12 10:25:36 -0400333 # validate that we need to use self_contained for plugins
christophe dervieuxf9bae672021-09-21 16:20:24 +0200334 if (self_contained) {
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200335 if (missing(reveal_plugins)) {
336 # the default plugin set collided with an explicitly requested
337 # self_contained render -- drop the defaults instead of failing
338 warning("Reveal plugins require self_contained: false -- ",
339 "rendering without the default plugins.",
340 call. = FALSE
341 )
342 reveal_plugins <- character(0)
343 } else {
344 stop("Using reveal_plugins requires self_contained: false")
345 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200346 }
347
JJ Allaire82a8dee2016-07-12 10:25:36 -0400348 # validate specified plugins are supported
JJ Allaire064552c2017-02-10 10:28:41 -0500349 supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu")
JJ Allaire82a8dee2016-07-12 10:25:36 -0400350 invalid_plugins <- setdiff(reveal_plugins, supported_plugins)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200351 if (length(invalid_plugins) > 0) {
JJ Allaire82a8dee2016-07-12 10:25:36 -0400352 stop("The following plugin(s) are not supported: ",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200353 paste(invalid_plugins, collapse = ", "),
354 call. = FALSE
355 )
356 }
357
JJ Allaire82a8dee2016-07-12 10:25:36 -0400358 # add plugins
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200359 if ("chalkboard" %in% reveal_plugins) {
360 # chalkboard require customcontrols so we add it to activate in the template
361 reveal_plugins <- c(reveal_plugins, "customcontrols")
362 }
JJ Allaire82a8dee2016-07-12 10:25:36 -0400363 sapply(reveal_plugins, function(plugin) {
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200364 args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin)))
365 if (plugin %in% c("customcontrols", "menu")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200366 extra_dependencies <<- append(
367 extra_dependencies,
368 list(rmarkdown::html_dependency_font_awesome())
369 )
JJ Allaire375805c2016-11-15 08:56:43 -0500370 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200371 })
JJ Allaire82a8dee2016-07-12 10:25:36 -0400372 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200373
JJ Allaire2ec40242014-09-15 09:18:39 -0400374 # content includes
375 args <- c(args, includes_to_pandoc_args(includes))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200376
JJ Allairefad55232015-10-19 07:47:26 -0400377 # additional css
christophe dervieuxf9bae672021-09-21 16:20:24 +0200378 for (css_file in css) {
JJ Allairefad55232015-10-19 07:47:26 -0400379 args <- c(args, "--css", pandoc_path_arg(css_file))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200380 }
381
JJ Allaire2ec40242014-09-15 09:18:39 -0400382 # pre-processor for arguments that may depend on the name of the
383 # the input file (e.g. ones that need to copy supporting files)
384 pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
385 output_dir) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200386
JJ Allairee60feb22016-01-30 18:28:47 -0500387 # we don't work with runtime shiny
388 if (identical(runtime, "shiny")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200389 stop("revealjs_presentation is not compatible with runtime 'shiny'",
390 call. = FALSE
391 )
JJ Allairee60feb22016-01-30 18:28:47 -0500392 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200393
JJ Allaire2ec40242014-09-15 09:18:39 -0400394 # use files_dir as lib_dir if not explicitly specified
christophe dervieuxf9bae672021-09-21 16:20:24 +0200395 if (is.null(lib_dir)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400396 lib_dir <- files_dir
christophe dervieuxf9bae672021-09-21 16:20:24 +0200397 }
398
JJ Allaire2ec40242014-09-15 09:18:39 -0400399 # extra args
400 args <- c()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200401
JJ Allaire2ec40242014-09-15 09:18:39 -0400402 # reveal.js
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200403 revealjs_path <- revealjs_lib_path()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200404 if (!self_contained || identical(.Platform$OS.type, "windows")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400405 revealjs_path <- relative_to(
christophe dervieuxf9bae672021-09-21 16:20:24 +0200406 output_dir, render_supporting_files(revealjs_path, lib_dir)
407 )
408 } else {
JJ Allaireeea3bca2016-07-13 12:42:01 -0400409 revealjs_path <- pandoc_path_arg(revealjs_path)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200410 }
christophe dervieux062940d2021-09-21 16:26:14 +0200411 args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200412
JJ Allaire2ec40242014-09-15 09:18:39 -0400413 # highlight
414 args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200415
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300416 # default to the bundled IDS citation style unless the document
417 # specifies a style of its own
418 if (is.null(metadata$csl)) {
419 args <- c(args, "--csl", pandoc_path_arg(reveal_resources("ids.csl")))
420 }
421
JJ Allaire2ec40242014-09-15 09:18:39 -0400422 # return additional args
423 args
424 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200425
Marc Kupietzb066e742026-08-23 09:57:06 +0300426 # post-processor converting <!-- MK 00:30 --> speaker timing comments into
427 # data-timing attributes on the enclosing sections (activating the pacing
428 # timer of the notes plugin) and reporting per-speaker totals
429 post_processor <- function(metadata, input_file, output_file, clean, verbose) {
430 lines <- readLines(output_file, warn = FALSE, encoding = "UTF-8")
Marc Kupietz6b65c032026-08-25 09:43:28 +0300431 lines <- merge_title_slide_notes(lines)
Marc Kupietzb066e742026-08-23 09:57:06 +0300432 result <- apply_timing_attributes(lines)
433 comments <- attr(result, "comments")
434 if (nrow(comments) > 0) {
435 result <- inject_total_time(result, sum(comments$seconds))
436 writeLines(enc2utf8(result), output_file, useBytes = TRUE)
437 message(timing_report_message(comments))
438 }
439 output_file
440 }
441
JJ Allaire2ec40242014-09-15 09:18:39 -0400442 # return format
443 output_format(
444 knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200445 pandoc = pandoc_options(
446 to = "revealjs",
christophe dervieuxad3a5752021-09-23 10:24:09 +0200447 from = from_rmarkdown(fig_caption, md_extensions),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200448 args = args
449 ),
JJ Allaire2ec40242014-09-15 09:18:39 -0400450 keep_md = keep_md,
451 clean_supporting = self_contained,
452 pre_processor = pre_processor,
Marc Kupietzb066e742026-08-23 09:57:06 +0300453 post_processor = post_processor,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200454 base_format = html_document_base(
christophe dervieux0acc6c92021-09-23 11:18:18 +0200455 lib_dir = lib_dir,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200456 self_contained = self_contained,
457 mathjax = mathjax,
458 pandoc_args = pandoc_args,
459 extra_dependencies = extra_dependencies,
460 ...
461 )
462 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400463}
464
465revealjs_themes <- function() {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200466 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200467 "default", # not used by reveal
Marc Kupietza737b1b2023-10-07 09:32:20 +0200468 "ids",
JJ Allaire2ec40242014-09-15 09:18:39 -0400469 "simple",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200470 "dark", # our alias for black
471 "black",
JJ Allaire2ec40242014-09-15 09:18:39 -0400472 "sky",
473 "beige",
474 "serif",
475 "solarized",
JJ Allaire2ec40242014-09-15 09:18:39 -0400476 "blood",
477 "moon",
junkka77fbf082015-03-15 22:25:47 +0100478 "night",
junkka77fbf082015-03-15 22:25:47 +0100479 "league",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200480 "white"
481 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400482}
483
JJ Allaire2ec40242014-09-15 09:18:39 -0400484revealjs_transitions <- function() {
junkka77fbf082015-03-15 22:25:47 +0100485 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200486 "default", # not used by reveal
487 "convex",
JJ Allaire2ec40242014-09-15 09:18:39 -0400488 "fade",
junkka77fbf082015-03-15 22:25:47 +0100489 "slide",
junkka77fbf082015-03-15 22:25:47 +0100490 "concave",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200491 "zoom",
492 "none"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200493 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400494}