blob: fa31dca8cc8d1b54afaf52817da0e3d7a407c4ca [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
Marc Kupietzb9a8cba2026-08-28 06:51:28 +030014#'
15#' The plugins `notes`, `search`, `menu` and `zoom` are activated by default;
16#' only `chalkboard` is opt-in. Setting `reveal_plugins` replaces the default
17#' set -- pass `NULL` to render without any plugins.
18#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020019#' ## Built-in plugins with reveal.js
Marc Kupietzb9a8cba2026-08-28 06:51:28 +030020#'
21#' ### Zoom
22#'
23#' Activated by default: ALT + Click can be used to zoom on a slide.
24#'
25#' ### Notes
26#'
27#' Activated by default: shows a [speaker view](https://revealjs.com/speaker-view/) in a separated
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020028#' window. This speaker view contains a timer, current slide, next slide, and
29#' speaker notes. It also duplicate the window to have presentation mode
30#' synchronized with main presentation.
31#'
32#' Use
33#' ```markdown
34#' ::: notes
35#' Content of speaker notes
36#' :::
37#' ```
Marc Kupietz6b65c032026-08-25 09:43:28 +030038#' to create notes only viewable in presentation mode. Notes placed before
39#' the first heading are attached to the title slide.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +020040#'
Marc Kupietz88799182026-08-24 09:22:33 +030041#' On mobile browsers (touch devices), a button next to the fullscreen
42#' toggle overlays the current slide with its speaker notes (plus the slide
43#' title and, if present, the planned time from a timing comment), which is
44#' useful for practicing a talk on a phone or tablet. It follows along as
45#' you change slides and only appears if the deck contains notes at all.
46#'
Marc Kupietz010db0b2026-08-26 09:56:45 +030047#' Pressing `r` -- or, on touch devices, tapping the list button next to
48#' the speaker notes button -- toggles a transcript view: a single
49#' scrollable page containing every slide's content and speaker notes.
50#' Text-to-speech ("read aloud") browser extensions cannot walk a
51#' reveal.js deck, since hidden slides are not part of the visible page
52#' text -- the transcript gives them something they can read from start
53#' to finish.
Marc Kupietzeaaa2b42026-08-26 09:41:27 +030054#'
Marc Kupietzb066e742026-08-23 09:57:06 +030055#' ## Slide timing
56#'
57#' Speaker time can be planned per slide and per speaker by adding a comment
58#' with a speaker code and the expected duration (in `MM:SS`, `HH:MM:SS`, or
59#' plain seconds format) anywhere inside a slide:
60#'
61#' ```markdown
62#' ## My slide title
63#'
64#' Some content
65#'
66#' <!-- MK 00:30 -->
67#' ```
68#'
69#' This means Marc Kupietz will need 30 seconds for that slide. For talks
70#' presented by a single speaker, the speaker code can be omitted:
Marc Kupietz6b65c032026-08-25 09:43:28 +030071#' `<!-- 00:30 -->`. Comments placed before the first heading are applied to
72#' the title slide.
Marc Kupietzb066e742026-08-23 09:57:06 +030073#'
74#' Typically you start from a known total time budget and adjust the
75#' individual slides to it. You can set this budget yourself with the
76#' reveal.js `totalTime` option (in seconds):
77#'
78#' ```yaml
79#' output:
80#' revealjs.ids::revealjs_presentation:
81#' reveal_options:
82#' totalTime: 3600 # one hour
83#' ```
84#'
85#' During rendering, comments are converted into `data-timing` attributes on
86#' the slides' `<section>` elements (several speakers per slide are summed
87#' up), and the calculated grand total is passed to reveal.js as the
88#' `totalTime` config value. This activates the pacing timer in the
89#' [speaker view](https://revealjs.com/speaker-view/), which shows how you
90#' are doing relative to your plan. A summary of the total time per speaker
91#' is printed during rendering. If the document sets `totalTime` or
92#' `defaultTiming` itself (via `reveal_options`), those take precedence.
93#'
94#' The function [slide_timing()] computes these totals directly from an
95#' `.Rmd` source file without rendering it.
96#'
Marc Kupietz4eb03202026-08-25 10:58:10 +030097#' ## Overview slides
98#'
99#' Like in the original Google Docs slide workflow, a slide titled
100#' "Overview" or "Überblick" is automatically turned into a table of
101#' contents: its body content is replaced at presentation time with a
102#' clickable list of all `#` chapter headings. Adding
103#' `{data-overview-subheadings=true}` to the heading also includes the
104#' `##` sub-headings below their chapters, laid out in two columns.
105#' References and appendix chapters (References/Literatur/
106#' Literaturverzeichnis/Appendix/Anhang) are left out, together with
107#' their sub-slides.
108#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200109#' ### Search
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300110#'
111#' Activated by default: pressing `CTRL + SHIFT + F` shows a search box.
112#' It will search in the whole presentation, and highlight matched words. The
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200113#' matches will also be highlighted in overview mode (pressing ESC to see all
114#' slides in one scrollable view)
115#'
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300116#' ## Menu
117#'
118#' Activated by default: a slideout menu plugin for Reveal.js to quickly jump
119#' to any slide by title.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200120#'
121#' Version `r version <- readLines(revealjs_lib_path("plugin", "menu", "VERSION"))` is
122#' currently used and documentation for configurations can be found at
123#' [denehyg/reveal.js-menu](https://github.com/denehyg/reveal.js-menu/blob/`r version`/README.md)
124#'
125#' ### Known limitations
126#'
127#' Some configurations cannot be modified in the current template:
128#'
129#' * `loadIcons: false` the fontawesome icons are loaded by \pkg{rmarkdown}
130#' when this plugin is used
131#' * `custom: false`
132#' * `themes: false`
133#' * `transitions: false`
134
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300135#' ## Chalkboard
136#'
137#' An opt-in plugin adding a chalkboard and slide annotation
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200138#'
139#' Version `r version <- readLines(revealjs_lib_path("plugin", "chalkboard", "VERSION"))` is
140#' currently used and documentation for configurations can be found at
141#' [rajgoel/reveal.js-plugins](https://github.com/rajgoel/reveal.js-plugins/tree/`r version`/4.1.5/chalkboard)
142#'
143#' By default, chalkboard and annotations modes will be accessible using keyboard
144#' shortcuts, respectively, pressing B, or pressing C.
145#' In addition, buttons on the bottom left can be added by using the following
146#'
147#' ```yaml
148#' reveal_plugins:
149#' - chalkboard
150#' reveal_options:
151#' chalkboard:
152#' toggleNotesButton: true
153#' toggleChalkboardButton: true
154#' ```
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300155#' ## Bibliography and citations
156#'
157#' Documents with a `bibliography:` in their YAML header are formatted with
158#' the bundled IDS citation style (`ids.csl`, based on the style developed
159#' for ICLC-10 2023 in Mannheim) by default. To use a different style,
160#' specify it as usual with `csl:` in the YAML header.
161#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400162#' @inheritParams rmarkdown::beamer_presentation
163#' @inheritParams rmarkdown::pdf_document
164#' @inheritParams rmarkdown::html_document
christophe dervieuxf9bae672021-09-21 16:20:24 +0200165#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200166#' @param center `TRUE` to vertically center content on slides
christophe dervieuxf9bae672021-09-21 16:20:24 +0200167#' @param slide_level Level of heading to denote individual slides. If
christophe dervieuxd26add32021-09-23 16:55:00 +0200168#' `slide_level` is 2 (the default), a two-dimensional layout will be
christophe dervieuxf9bae672021-09-21 16:20:24 +0200169#' produced, with level 1 headers building horizontally and level 2 headers
170#' building vertically. It is not recommended that you use deeper nesting of
JJ Allaire4c178052016-01-30 19:35:39 -0500171#' section levels with reveal.js.
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300172#' @param theme Visual theme. Defaults to the dedicated IDS corporate design
173#' theme ("ids"), which is the raison d'être of this package; the stock
174#' reveal.js themes are available as rarely used alternatives:
175#' `r knitr::combine_words(setdiff(revealjs_themes(), c("default", "ids")), before = '"', and = " or ")`
176#' ("dark" is an alias for "black").
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200177#' @param transition Slide transition (
178#' `r (trans <- knitr::combine_words(setdiff(revealjs_transitions(), "default"), before = '"', and = " or "))`
179#' )
180#' @param background_transition Slide background-transition (
181#' `r trans`
182#' )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200183#' @param reveal_options Additional options to specify for reveal.js (see
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200184#' <https://revealjs.com/config/> for details). Options for plugins can also
185#' be passed, using plugin name as first level key (e.g `list(slideNumber =
186#' FALSE, menu = list(number = TRUE))`).
JJ Allaire35c0b492017-02-10 09:30:24 -0500187#' @param reveal_plugins Reveal plugins to include. Available plugins include
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200188#' "notes", "search", "zoom", "chalkboard", and "menu". Defaults to
189#' `c("notes", "search", "menu", "zoom")`; pass `NULL` to render without
190#' any plugins. Note that `self_contained` must be set to `FALSE` in order
191#' to use Reveal plugins.
christophe dervieuxf9bae672021-09-21 16:20:24 +0200192#' @param template Pandoc template to use for rendering. Pass "default" to use
christophe dervieuxd26add32021-09-23 16:55:00 +0200193#' the rmarkdown package default template; pass `NULL` to use pandoc's
christophe dervieuxf9bae672021-09-21 16:20:24 +0200194#' built-in template; pass a path to use a custom template that you've
195#' created. Note that if you don't use the "default" template then some
christophe dervieuxd26add32021-09-23 16:55:00 +0200196#' features of `revealjs_presentation` won't be available (see the
JJ Allaire4c178052016-01-30 19:35:39 -0500197#' Templates section below for more details).
JJ Allaire35c0b492017-02-10 09:30:24 -0500198#' @param extra_dependencies Additional function arguments to pass to the base R
199#' Markdown HTML output formatter [rmarkdown::html_document_base()].
JJ Allaire8d1c2f42016-01-30 14:56:45 -0500200#' @param ... Ignored
christophe dervieuxf9bae672021-09-21 16:20:24 +0200201#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200202#' @return R Markdown output format to pass to [rmarkdown::render()]
christophe dervieuxf9bae672021-09-21 16:20:24 +0200203#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400204#' @examples
205#' \dontrun{
christophe dervieuxf9bae672021-09-21 16:20:24 +0200206#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400207#' library(rmarkdown)
Marc Kupietze195cea2026-08-17 13:17:33 +0200208#' library(revealjs.ids)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200209#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400210#' # simple invocation
211#' render("pres.Rmd", revealjs_presentation())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200212#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400213#' # specify an option for incremental rendering
214#' render("pres.Rmd", revealjs_presentation(incremental = TRUE))
215#' }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200216#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400217#' @export
218revealjs_presentation <- function(incremental = FALSE,
219 center = FALSE,
JJ Allaire4c178052016-01-30 19:35:39 -0500220 slide_level = 2,
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200221 toc = FALSE,
222 toc_depth = 3,
JJ Allaire2ec40242014-09-15 09:18:39 -0400223 fig_width = 8,
224 fig_height = 6,
225 fig_retina = if (!fig_caption) 2,
226 fig_caption = FALSE,
Marc Kupietzf8d5ff12023-10-09 18:58:09 +0200227 self_contained = FALSE,
228 theme = "ids",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200229 transition = "convex",
230 background_transition = "fade",
JJ Allaire37f45b72016-01-30 18:17:45 -0500231 reveal_options = NULL,
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200232 reveal_plugins = c("notes", "search", "menu", "zoom"),
JJ Allaire2ec40242014-09-15 09:18:39 -0400233 highlight = "default",
234 mathjax = "default",
235 template = "default",
JJ Allairefad55232015-10-19 07:47:26 -0400236 css = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400237 includes = NULL,
238 keep_md = FALSE,
239 lib_dir = NULL,
240 pandoc_args = NULL,
JJ Allaire375805c2016-11-15 08:56:43 -0500241 extra_dependencies = NULL,
Atsushi Yasumoto0bf44442020-02-15 00:08:30 +0900242 md_extensions = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400243 ...) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200244
JJ Allaire2ec40242014-09-15 09:18:39 -0400245 # base pandoc options for all reveal.js output
246 args <- c()
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200247
248 # table of contents
249 args <- c(args, pandoc_toc_args(toc, toc_depth))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200250
JJ Allaire2ec40242014-09-15 09:18:39 -0400251 # template path and assets
JJ Allairea8c414b2016-01-30 14:36:53 -0500252 if (identical(template, "default")) {
christophe dervieux92fa4692021-09-21 16:15:17 +0200253 default_template <- reveal_resources("default.html")
JJ Allairea8c414b2016-01-30 14:36:53 -0500254 args <- c(args, "--template", pandoc_path_arg(default_template))
255 } else if (!is.null(template)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400256 args <- c(args, "--template", pandoc_path_arg(template))
JJ Allairea8c414b2016-01-30 14:36:53 -0500257 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200258
JJ Allaire2ec40242014-09-15 09:18:39 -0400259 # incremental
christophe dervieuxf9bae672021-09-21 16:20:24 +0200260 if (incremental) args <- c(args, "--incremental")
261
JJ Allaire2ec40242014-09-15 09:18:39 -0400262 # centering
JJ Allaire40fec332016-01-30 16:54:51 -0500263 args <- c(args, pandoc_variable_arg("center", jsbool(center)))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200264
JJ Allaire4c178052016-01-30 19:35:39 -0500265 # slide level
JJ Allairec58a6c42016-03-30 23:45:21 -0400266 args <- c(args, "--slide-level", as.character(slide_level))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200267
JJ Allaire2ec40242014-09-15 09:18:39 -0400268 # theme
269 theme <- match.arg(theme, revealjs_themes())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200270 if (identical(theme, "default")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400271 theme <- "simple"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200272 } else if (identical(theme, "dark")) {
JJ Allaire6da1bb62016-01-30 14:28:39 -0500273 theme <- "black"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200274 }
275 if (theme %in% c("blood", "moon", "night", "black")) {
christophe dervieux062940d2021-09-21 16:26:14 +0200276 args <- c(args, pandoc_variable_arg("theme-dark"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200277 }
christophe dervieux1ebd5132021-09-22 08:47:21 +0200278 args <- c(args, pandoc_variable_arg("theme", theme))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200279
Marc Kupietz7c8f7de2023-10-07 11:42:29 +0200280 if (theme == "ids") {
281 args <- c(args, pandoc_variable_arg("theme-ids"))
282 fig_height = 7
283 fig_width = 12
284 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200285
JJ Allaire2ec40242014-09-15 09:18:39 -0400286 # transition
Marc Kupietz9d96fda2026-08-11 16:55:13 +0200287 if (missing(transition) && identical(theme, "ids")) {
288 # IDS theme: slide the slides in instead of rotating them (reveal.js'
289 # own default, convex), unless the user explicitly asked for something
290 # else. The formal default has to stay "convex" for the other themes.
291 transition <- "slide"
292 }
JJ Allaire2ec40242014-09-15 09:18:39 -0400293 transition <- match.arg(transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200294 if (identical(transition, "default")) {
295 # revealjs default is convex
296 transition <- "convex"
297 }
christophe dervieux062940d2021-09-21 16:26:14 +0200298 args <- c(args, pandoc_variable_arg("transition", transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200299
junkkad55cff02015-03-15 22:27:03 +0100300 # background_transition
301 background_transition <- match.arg(background_transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200302 if (identical(background_transition, "default")) {
303 # revealjs default is fade
304 background_transition <- "fade"
305 }
christophe dervieux062940d2021-09-21 16:26:14 +0200306 args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200307
JJ Allaire4ae486f2016-03-23 06:08:42 -0400308 # use history
309 args <- c(args, pandoc_variable_arg("history", "true"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200310
Marc Kupietza0f8f682026-08-08 14:13:11 +0200311 # The IDS corporate design puts the orange bar flush against the top left
312 # corner of the slide. reveal.js defaults to margin = 0.04, i.e. it keeps 4%
313 # of the display empty around the content, which would leave a white border
314 # above and to the left of the bar. Default to 0 instead, unless the document
315 # asks for a margin of its own via reveal_options.
316 if (!is.list(reveal_options) || is.null(reveal_options[["margin"]])) {
317 args <- c(args, pandoc_variable_arg("margin", "0"))
318 }
319
JJ Allaire37f45b72016-01-30 18:17:45 -0500320 # additional reveal options
321 if (is.list(reveal_options)) {
JJ Allaire375805c2016-11-15 08:56:43 -0500322 for (option in names(reveal_options)) {
JJ Allaire064552c2017-02-10 10:28:41 -0500323 # special handling for nested options
324 if (option %in% c("chalkboard", "menu")) {
325 nested_options <- reveal_options[[option]]
326 for (nested_option in names(nested_options)) {
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200327 args <- c(args,
328 process_reveal_option(
329 paste0(option, "-", nested_option),
330 nested_options[[nested_option]]
331 )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200332 )
JJ Allaire375805c2016-11-15 08:56:43 -0500333 }
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200334 } else {
335 # standard top-level options
336 args <- c(args, process_reveal_option(option, reveal_options[[option]]))
JJ Allaire375805c2016-11-15 08:56:43 -0500337 }
JJ Allaire37f45b72016-01-30 18:17:45 -0500338 }
339 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200340
JJ Allaire82a8dee2016-07-12 10:25:36 -0400341 # reveal plugins
342 if (is.character(reveal_plugins)) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200343
JJ Allaire82a8dee2016-07-12 10:25:36 -0400344 # validate that we need to use self_contained for plugins
christophe dervieuxf9bae672021-09-21 16:20:24 +0200345 if (self_contained) {
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200346 if (missing(reveal_plugins)) {
347 # the default plugin set collided with an explicitly requested
348 # self_contained render -- drop the defaults instead of failing
349 warning("Reveal plugins require self_contained: false -- ",
350 "rendering without the default plugins.",
351 call. = FALSE
352 )
353 reveal_plugins <- character(0)
354 } else {
355 stop("Using reveal_plugins requires self_contained: false")
356 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200357 }
358
JJ Allaire82a8dee2016-07-12 10:25:36 -0400359 # validate specified plugins are supported
JJ Allaire064552c2017-02-10 10:28:41 -0500360 supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu")
JJ Allaire82a8dee2016-07-12 10:25:36 -0400361 invalid_plugins <- setdiff(reveal_plugins, supported_plugins)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200362 if (length(invalid_plugins) > 0) {
JJ Allaire82a8dee2016-07-12 10:25:36 -0400363 stop("The following plugin(s) are not supported: ",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200364 paste(invalid_plugins, collapse = ", "),
365 call. = FALSE
366 )
367 }
368
JJ Allaire82a8dee2016-07-12 10:25:36 -0400369 # add plugins
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200370 if ("chalkboard" %in% reveal_plugins) {
371 # chalkboard require customcontrols so we add it to activate in the template
372 reveal_plugins <- c(reveal_plugins, "customcontrols")
373 }
JJ Allaire82a8dee2016-07-12 10:25:36 -0400374 sapply(reveal_plugins, function(plugin) {
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200375 args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin)))
376 if (plugin %in% c("customcontrols", "menu")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200377 extra_dependencies <<- append(
378 extra_dependencies,
379 list(rmarkdown::html_dependency_font_awesome())
380 )
JJ Allaire375805c2016-11-15 08:56:43 -0500381 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200382 })
JJ Allaire82a8dee2016-07-12 10:25:36 -0400383 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200384
JJ Allaire2ec40242014-09-15 09:18:39 -0400385 # content includes
386 args <- c(args, includes_to_pandoc_args(includes))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200387
JJ Allairefad55232015-10-19 07:47:26 -0400388 # additional css
christophe dervieuxf9bae672021-09-21 16:20:24 +0200389 for (css_file in css) {
JJ Allairefad55232015-10-19 07:47:26 -0400390 args <- c(args, "--css", pandoc_path_arg(css_file))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200391 }
392
JJ Allaire2ec40242014-09-15 09:18:39 -0400393 # pre-processor for arguments that may depend on the name of the
394 # the input file (e.g. ones that need to copy supporting files)
395 pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
396 output_dir) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200397
JJ Allairee60feb22016-01-30 18:28:47 -0500398 # we don't work with runtime shiny
399 if (identical(runtime, "shiny")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200400 stop("revealjs_presentation is not compatible with runtime 'shiny'",
401 call. = FALSE
402 )
JJ Allairee60feb22016-01-30 18:28:47 -0500403 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200404
JJ Allaire2ec40242014-09-15 09:18:39 -0400405 # use files_dir as lib_dir if not explicitly specified
christophe dervieuxf9bae672021-09-21 16:20:24 +0200406 if (is.null(lib_dir)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400407 lib_dir <- files_dir
christophe dervieuxf9bae672021-09-21 16:20:24 +0200408 }
409
JJ Allaire2ec40242014-09-15 09:18:39 -0400410 # extra args
411 args <- c()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200412
JJ Allaire2ec40242014-09-15 09:18:39 -0400413 # reveal.js
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200414 revealjs_path <- revealjs_lib_path()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200415 if (!self_contained || identical(.Platform$OS.type, "windows")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400416 revealjs_path <- relative_to(
christophe dervieuxf9bae672021-09-21 16:20:24 +0200417 output_dir, render_supporting_files(revealjs_path, lib_dir)
418 )
419 } else {
JJ Allaireeea3bca2016-07-13 12:42:01 -0400420 revealjs_path <- pandoc_path_arg(revealjs_path)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200421 }
christophe dervieux062940d2021-09-21 16:26:14 +0200422 args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200423
JJ Allaire2ec40242014-09-15 09:18:39 -0400424 # highlight
425 args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200426
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300427 # default to the bundled IDS citation style unless the document
428 # specifies a style of its own
429 if (is.null(metadata$csl)) {
430 args <- c(args, "--csl", pandoc_path_arg(reveal_resources("ids.csl")))
431 }
432
JJ Allaire2ec40242014-09-15 09:18:39 -0400433 # return additional args
434 args
435 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200436
Marc Kupietzb066e742026-08-23 09:57:06 +0300437 # post-processor converting <!-- MK 00:30 --> speaker timing comments into
438 # data-timing attributes on the enclosing sections (activating the pacing
439 # timer of the notes plugin) and reporting per-speaker totals
440 post_processor <- function(metadata, input_file, output_file, clean, verbose) {
441 lines <- readLines(output_file, warn = FALSE, encoding = "UTF-8")
Marc Kupietz6b65c032026-08-25 09:43:28 +0300442 lines <- merge_title_slide_notes(lines)
Marc Kupietzb066e742026-08-23 09:57:06 +0300443 result <- apply_timing_attributes(lines)
444 comments <- attr(result, "comments")
445 if (nrow(comments) > 0) {
446 result <- inject_total_time(result, sum(comments$seconds))
447 writeLines(enc2utf8(result), output_file, useBytes = TRUE)
448 message(timing_report_message(comments))
449 }
450 output_file
451 }
452
JJ Allaire2ec40242014-09-15 09:18:39 -0400453 # return format
454 output_format(
455 knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200456 pandoc = pandoc_options(
457 to = "revealjs",
christophe dervieuxad3a5752021-09-23 10:24:09 +0200458 from = from_rmarkdown(fig_caption, md_extensions),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200459 args = args
460 ),
JJ Allaire2ec40242014-09-15 09:18:39 -0400461 keep_md = keep_md,
462 clean_supporting = self_contained,
463 pre_processor = pre_processor,
Marc Kupietzb066e742026-08-23 09:57:06 +0300464 post_processor = post_processor,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200465 base_format = html_document_base(
christophe dervieux0acc6c92021-09-23 11:18:18 +0200466 lib_dir = lib_dir,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200467 self_contained = self_contained,
468 mathjax = mathjax,
469 pandoc_args = pandoc_args,
470 extra_dependencies = extra_dependencies,
471 ...
472 )
473 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400474}
475
476revealjs_themes <- function() {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200477 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200478 "default", # not used by reveal
Marc Kupietza737b1b2023-10-07 09:32:20 +0200479 "ids",
JJ Allaire2ec40242014-09-15 09:18:39 -0400480 "simple",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200481 "dark", # our alias for black
482 "black",
JJ Allaire2ec40242014-09-15 09:18:39 -0400483 "sky",
484 "beige",
485 "serif",
486 "solarized",
JJ Allaire2ec40242014-09-15 09:18:39 -0400487 "blood",
488 "moon",
junkka77fbf082015-03-15 22:25:47 +0100489 "night",
junkka77fbf082015-03-15 22:25:47 +0100490 "league",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200491 "white"
492 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400493}
494
JJ Allaire2ec40242014-09-15 09:18:39 -0400495revealjs_transitions <- function() {
junkka77fbf082015-03-15 22:25:47 +0100496 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200497 "default", # not used by reveal
498 "convex",
JJ Allaire2ec40242014-09-15 09:18:39 -0400499 "fade",
junkka77fbf082015-03-15 22:25:47 +0100500 "slide",
junkka77fbf082015-03-15 22:25:47 +0100501 "concave",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200502 "zoom",
503 "none"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200504 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400505}