blob: d93e61729906ea4c93b77ba22f40840d14f84af8 [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 Kupietzde3c6c12026-08-30 14:40:33 +030097#' ## Vertical content centering
98#'
99#' Slides with little content look lost when everything is glued below the
100#' title bar, while packed slides must start at the top. reveal.js' own
101#' `center` option cannot express this -- it also vertically centers the
102#' headings. Instead, the body content of each slide (everything after the
103#' heading block except speaker notes) is grouped and, whenever there is
104#' free space, centered in the area between the heading and the footer:
105#' slides that are too packed simply start directly below the heading and
106#' overflow downwards, exactly as before. Centered content never reaches
107#' into the footer; content too tall to fit above it may, as it always
108#' could. Heading-only section-divider slides keep their own centered-title
109#' layout. No configuration is needed and nothing changes about how slides
110#' are authored.
111#'
Marc Kupietzde3ffa42026-08-30 13:47:57 +0300112#' ## Chapter numbering
113#'
114#' Like in the old Google Docs slide workflow, chapter headings (`#`) are
115#' numbered automatically: the first chapter becomes "1. Introduction", the
116#' second "2. Methods", and so on. References, appendix and thank-you
117#' chapters (References/Literatur/Referenzen/Publikationen/
118#' Herausgeberschaften/Appendix/Anhang, and headings containing
119#' "Thank you"/"Vielen Dank") keep their bare titles and are not counted.
120#' Manually typed leading numbers (`# 2. Methods`) are stripped before
121#' renumbering, so decks migrated from the old pipeline and repeated
122#' numbering runs stay stable. The numbers are added when the presentation
123#' is opened: the menu plugin and the transcript view show them, too, and
124#' the overview slide's table of contents uses them as its ordered list's
125#' enumeration. Decks rendered with `slide_level = 1` (one `#` heading per
126#' slide) are left unnumbered -- there, headings denote slides, not
127#' chapters.
128#'
Marc Kupietz4eb03202026-08-25 10:58:10 +0300129#' ## Overview slides
130#'
131#' Like in the original Google Docs slide workflow, a slide titled
132#' "Overview" or "Überblick" is automatically turned into a table of
133#' contents: its body content is replaced at presentation time with a
Marc Kupietzde3ffa42026-08-30 13:47:57 +0300134#' clickable, ordered list of all `#` chapter headings, whose enumeration
135#' repeats the chapter numbers. Adding
Marc Kupietz4eb03202026-08-25 10:58:10 +0300136#' `{data-overview-subheadings=true}` to the heading also includes the
137#' `##` sub-headings below their chapters, laid out in two columns.
Marc Kupietzde3ffa42026-08-30 13:47:57 +0300138#' References, appendix and thank-you chapters (References/Literatur/
139#' Literaturverzeichnis/Referenzen/Publikationen/Herausgeberschaften/
140#' Appendix/Anhang, and headings containing "Thank you"/"Vielen Dank") are
141#' left out, together with their sub-slides.
Marc Kupietz4eb03202026-08-25 10:58:10 +0300142#'
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200143#' ### Search
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300144#'
145#' Activated by default: pressing `CTRL + SHIFT + F` shows a search box.
146#' It will search in the whole presentation, and highlight matched words. The
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200147#' matches will also be highlighted in overview mode (pressing ESC to see all
148#' slides in one scrollable view)
149#'
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300150#' ## Menu
151#'
152#' Activated by default: a slideout menu plugin for Reveal.js to quickly jump
153#' to any slide by title.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200154#'
155#' Version `r version <- readLines(revealjs_lib_path("plugin", "menu", "VERSION"))` is
156#' currently used and documentation for configurations can be found at
157#' [denehyg/reveal.js-menu](https://github.com/denehyg/reveal.js-menu/blob/`r version`/README.md)
158#'
159#' ### Known limitations
160#'
161#' Some configurations cannot be modified in the current template:
162#'
163#' * `loadIcons: false` the fontawesome icons are loaded by \pkg{rmarkdown}
164#' when this plugin is used
165#' * `custom: false`
166#' * `themes: false`
167#' * `transitions: false`
168
Marc Kupietzb9a8cba2026-08-28 06:51:28 +0300169#' ## Chalkboard
170#'
171#' An opt-in plugin adding a chalkboard and slide annotation
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200172#'
173#' Version `r version <- readLines(revealjs_lib_path("plugin", "chalkboard", "VERSION"))` is
174#' currently used and documentation for configurations can be found at
175#' [rajgoel/reveal.js-plugins](https://github.com/rajgoel/reveal.js-plugins/tree/`r version`/4.1.5/chalkboard)
176#'
177#' By default, chalkboard and annotations modes will be accessible using keyboard
178#' shortcuts, respectively, pressing B, or pressing C.
179#' In addition, buttons on the bottom left can be added by using the following
180#'
181#' ```yaml
182#' reveal_plugins:
183#' - chalkboard
184#' reveal_options:
185#' chalkboard:
186#' toggleNotesButton: true
187#' toggleChalkboardButton: true
188#' ```
Marc Kupietz59e95a62026-08-29 10:19:05 +0300189#' ## Title slide: QR code and additional logos
190#'
191#' Three optional yaml entries personalise the title slide for external
192#' audiences (ported from \pkg{posterdown.ids}):
193#'
194#' * `website: <url>` -- a linked QR code pointing to the URL is placed in
195#' the top left of the title slide. Uses the \pkg{qrcode} package.
196#' * `partner_logo: <path-or-url>` -- when a presentation is given by
197#' authors from two institutions, the partner institution's logo is shown
198#' next to the IDS logo, in the top right of every slide.
199#' * `funder_logo: <path-or-url>` -- a funder logo (e.g. "Text+") is placed
200#' in the bottom left of the title slide, opposite the Leibniz
201#' Gemeinschaft membership logo. It is lifted above the footer band on
202#' print (pdf) pages.
203#'
204#' Local logo files (svg, png, jpg, gif, webp) are embedded in the html as
205#' data URIs, so they do not need to be shipped with the presentation; http
206#' URLs are used as-is. A QR code anywhere else on a slide can be produced
207#' with [qrlink()] from inline R code. The navigation chrome (arrows, slide
208#' number, menu button) is hidden on the title slide for a bare first
209#' impression.
210#'
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300211#' ## Bibliography and citations
212#'
213#' Documents with a `bibliography:` in their YAML header are formatted with
214#' the bundled IDS citation style (`ids.csl`, based on the style developed
215#' for ICLC-10 2023 in Mannheim) by default. To use a different style,
216#' specify it as usual with `csl:` in the YAML header.
217#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400218#' @inheritParams rmarkdown::beamer_presentation
219#' @inheritParams rmarkdown::pdf_document
220#' @inheritParams rmarkdown::html_document
christophe dervieuxf9bae672021-09-21 16:20:24 +0200221#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200222#' @param center `TRUE` to vertically center content on slides
christophe dervieuxf9bae672021-09-21 16:20:24 +0200223#' @param slide_level Level of heading to denote individual slides. If
christophe dervieuxd26add32021-09-23 16:55:00 +0200224#' `slide_level` is 2 (the default), a two-dimensional layout will be
christophe dervieuxf9bae672021-09-21 16:20:24 +0200225#' produced, with level 1 headers building horizontally and level 2 headers
226#' building vertically. It is not recommended that you use deeper nesting of
JJ Allaire4c178052016-01-30 19:35:39 -0500227#' section levels with reveal.js.
Marc Kupietz9fdf0f72026-08-28 07:04:25 +0300228#' @param theme Visual theme. The dedicated IDS corporate design theme
229#' ("ids") is the default and the only supported theme.
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200230#' @param transition Slide transition (
231#' `r (trans <- knitr::combine_words(setdiff(revealjs_transitions(), "default"), before = '"', and = " or "))`
232#' )
233#' @param background_transition Slide background-transition (
234#' `r trans`
235#' )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200236#' @param reveal_options Additional options to specify for reveal.js (see
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200237#' <https://revealjs.com/config/> for details). Options for plugins can also
238#' be passed, using plugin name as first level key (e.g `list(slideNumber =
239#' FALSE, menu = list(number = TRUE))`).
JJ Allaire35c0b492017-02-10 09:30:24 -0500240#' @param reveal_plugins Reveal plugins to include. Available plugins include
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200241#' "notes", "search", "zoom", "chalkboard", and "menu". Defaults to
242#' `c("notes", "search", "menu", "zoom")`; pass `NULL` to render without
243#' any plugins. Note that `self_contained` must be set to `FALSE` in order
244#' to use Reveal plugins.
Marc Kupietz725acd12026-08-28 14:03:21 +0300245#' @param df_print Method used to print data frames in the document. The
246#' default, `"kable"`, renders data frames as plain HTML tables styled by
247#' the presentation theme, so that results look reasonable on slides without
248#' any extra code. Since `"kable"` prints all rows, consider showing only
249#' `head(x)` on slides with many-rowed results. Other supported methods are
250#' `"default"` (plain text output), `"tibble"`, and `"paged"` (an
251#' interactive paged table, see [rmarkdown::html_document()]).
christophe dervieuxf9bae672021-09-21 16:20:24 +0200252#' @param template Pandoc template to use for rendering. Pass "default" to use
christophe dervieuxd26add32021-09-23 16:55:00 +0200253#' the rmarkdown package default template; pass `NULL` to use pandoc's
christophe dervieuxf9bae672021-09-21 16:20:24 +0200254#' built-in template; pass a path to use a custom template that you've
255#' created. Note that if you don't use the "default" template then some
christophe dervieuxd26add32021-09-23 16:55:00 +0200256#' features of `revealjs_presentation` won't be available (see the
JJ Allaire4c178052016-01-30 19:35:39 -0500257#' Templates section below for more details).
JJ Allaire35c0b492017-02-10 09:30:24 -0500258#' @param extra_dependencies Additional function arguments to pass to the base R
259#' Markdown HTML output formatter [rmarkdown::html_document_base()].
JJ Allaire8d1c2f42016-01-30 14:56:45 -0500260#' @param ... Ignored
christophe dervieuxf9bae672021-09-21 16:20:24 +0200261#'
christophe dervieuxd26add32021-09-23 16:55:00 +0200262#' @return R Markdown output format to pass to [rmarkdown::render()]
christophe dervieuxf9bae672021-09-21 16:20:24 +0200263#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400264#' @examples
265#' \dontrun{
christophe dervieuxf9bae672021-09-21 16:20:24 +0200266#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400267#' library(rmarkdown)
Marc Kupietze195cea2026-08-17 13:17:33 +0200268#' library(revealjs.ids)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200269#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400270#' # simple invocation
271#' render("pres.Rmd", revealjs_presentation())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200272#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400273#' # specify an option for incremental rendering
274#' render("pres.Rmd", revealjs_presentation(incremental = TRUE))
275#' }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200276#'
JJ Allaire2ec40242014-09-15 09:18:39 -0400277#' @export
278revealjs_presentation <- function(incremental = FALSE,
279 center = FALSE,
JJ Allaire4c178052016-01-30 19:35:39 -0500280 slide_level = 2,
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200281 toc = FALSE,
282 toc_depth = 3,
JJ Allaire2ec40242014-09-15 09:18:39 -0400283 fig_width = 8,
284 fig_height = 6,
285 fig_retina = if (!fig_caption) 2,
286 fig_caption = FALSE,
Marc Kupietzf8d5ff12023-10-09 18:58:09 +0200287 self_contained = FALSE,
288 theme = "ids",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200289 transition = "convex",
290 background_transition = "fade",
JJ Allaire37f45b72016-01-30 18:17:45 -0500291 reveal_options = NULL,
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200292 reveal_plugins = c("notes", "search", "menu", "zoom"),
JJ Allaire2ec40242014-09-15 09:18:39 -0400293 highlight = "default",
Marc Kupietz725acd12026-08-28 14:03:21 +0300294 df_print = "kable",
JJ Allaire2ec40242014-09-15 09:18:39 -0400295 mathjax = "default",
296 template = "default",
JJ Allairefad55232015-10-19 07:47:26 -0400297 css = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400298 includes = NULL,
299 keep_md = FALSE,
300 lib_dir = NULL,
301 pandoc_args = NULL,
JJ Allaire375805c2016-11-15 08:56:43 -0500302 extra_dependencies = NULL,
Atsushi Yasumoto0bf44442020-02-15 00:08:30 +0900303 md_extensions = NULL,
JJ Allaire2ec40242014-09-15 09:18:39 -0400304 ...) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200305
JJ Allaire2ec40242014-09-15 09:18:39 -0400306 # base pandoc options for all reveal.js output
307 args <- c()
Christophe Dervieuxaa008e42021-09-23 16:52:37 +0200308
309 # table of contents
310 args <- c(args, pandoc_toc_args(toc, toc_depth))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200311
JJ Allaire2ec40242014-09-15 09:18:39 -0400312 # template path and assets
JJ Allairea8c414b2016-01-30 14:36:53 -0500313 if (identical(template, "default")) {
christophe dervieux92fa4692021-09-21 16:15:17 +0200314 default_template <- reveal_resources("default.html")
JJ Allairea8c414b2016-01-30 14:36:53 -0500315 args <- c(args, "--template", pandoc_path_arg(default_template))
316 } else if (!is.null(template)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400317 args <- c(args, "--template", pandoc_path_arg(template))
JJ Allairea8c414b2016-01-30 14:36:53 -0500318 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200319
JJ Allaire2ec40242014-09-15 09:18:39 -0400320 # incremental
christophe dervieuxf9bae672021-09-21 16:20:24 +0200321 if (incremental) args <- c(args, "--incremental")
322
JJ Allaire2ec40242014-09-15 09:18:39 -0400323 # centering
JJ Allaire40fec332016-01-30 16:54:51 -0500324 args <- c(args, pandoc_variable_arg("center", jsbool(center)))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200325
JJ Allaire4c178052016-01-30 19:35:39 -0500326 # slide level
JJ Allairec58a6c42016-03-30 23:45:21 -0400327 args <- c(args, "--slide-level", as.character(slide_level))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200328
JJ Allaire2ec40242014-09-15 09:18:39 -0400329 # theme
330 theme <- match.arg(theme, revealjs_themes())
christophe dervieuxf9bae672021-09-21 16:20:24 +0200331 if (identical(theme, "default")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400332 theme <- "simple"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200333 } else if (identical(theme, "dark")) {
JJ Allaire6da1bb62016-01-30 14:28:39 -0500334 theme <- "black"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200335 }
336 if (theme %in% c("blood", "moon", "night", "black")) {
christophe dervieux062940d2021-09-21 16:26:14 +0200337 args <- c(args, pandoc_variable_arg("theme-dark"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200338 }
christophe dervieux1ebd5132021-09-22 08:47:21 +0200339 args <- c(args, pandoc_variable_arg("theme", theme))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200340
Marc Kupietz7c8f7de2023-10-07 11:42:29 +0200341 if (theme == "ids") {
342 args <- c(args, pandoc_variable_arg("theme-ids"))
343 fig_height = 7
344 fig_width = 12
345 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200346
JJ Allaire2ec40242014-09-15 09:18:39 -0400347 # transition
Marc Kupietz9d96fda2026-08-11 16:55:13 +0200348 if (missing(transition) && identical(theme, "ids")) {
349 # IDS theme: slide the slides in instead of rotating them (reveal.js'
350 # own default, convex), unless the user explicitly asked for something
351 # else. The formal default has to stay "convex" for the other themes.
352 transition <- "slide"
353 }
JJ Allaire2ec40242014-09-15 09:18:39 -0400354 transition <- match.arg(transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200355 if (identical(transition, "default")) {
356 # revealjs default is convex
357 transition <- "convex"
358 }
christophe dervieux062940d2021-09-21 16:26:14 +0200359 args <- c(args, pandoc_variable_arg("transition", transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200360
junkkad55cff02015-03-15 22:27:03 +0100361 # background_transition
362 background_transition <- match.arg(background_transition, revealjs_transitions())
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200363 if (identical(background_transition, "default")) {
364 # revealjs default is fade
365 background_transition <- "fade"
366 }
christophe dervieux062940d2021-09-21 16:26:14 +0200367 args <- c(args, pandoc_variable_arg("backgroundTransition", background_transition))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200368
JJ Allaire4ae486f2016-03-23 06:08:42 -0400369 # use history
370 args <- c(args, pandoc_variable_arg("history", "true"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200371
Marc Kupietza0f8f682026-08-08 14:13:11 +0200372 # The IDS corporate design puts the orange bar flush against the top left
373 # corner of the slide. reveal.js defaults to margin = 0.04, i.e. it keeps 4%
374 # of the display empty around the content, which would leave a white border
375 # above and to the left of the bar. Default to 0 instead, unless the document
376 # asks for a margin of its own via reveal_options.
377 if (!is.list(reveal_options) || is.null(reveal_options[["margin"]])) {
378 args <- c(args, pandoc_variable_arg("margin", "0"))
379 }
380
JJ Allaire37f45b72016-01-30 18:17:45 -0500381 # additional reveal options
382 if (is.list(reveal_options)) {
JJ Allaire375805c2016-11-15 08:56:43 -0500383 for (option in names(reveal_options)) {
JJ Allaire064552c2017-02-10 10:28:41 -0500384 # special handling for nested options
385 if (option %in% c("chalkboard", "menu")) {
386 nested_options <- reveal_options[[option]]
387 for (nested_option in names(nested_options)) {
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200388 args <- c(args,
389 process_reveal_option(
390 paste0(option, "-", nested_option),
391 nested_options[[nested_option]]
392 )
christophe dervieuxf9bae672021-09-21 16:20:24 +0200393 )
JJ Allaire375805c2016-11-15 08:56:43 -0500394 }
Christophe Dervieux2f01dc92021-09-22 09:37:18 +0200395 } else {
396 # standard top-level options
397 args <- c(args, process_reveal_option(option, reveal_options[[option]]))
JJ Allaire375805c2016-11-15 08:56:43 -0500398 }
JJ Allaire37f45b72016-01-30 18:17:45 -0500399 }
400 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200401
JJ Allaire82a8dee2016-07-12 10:25:36 -0400402 # reveal plugins
403 if (is.character(reveal_plugins)) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200404
JJ Allaire82a8dee2016-07-12 10:25:36 -0400405 # validate that we need to use self_contained for plugins
christophe dervieuxf9bae672021-09-21 16:20:24 +0200406 if (self_contained) {
Marc Kupietz03dbc5d2026-08-21 15:44:25 +0200407 if (missing(reveal_plugins)) {
408 # the default plugin set collided with an explicitly requested
409 # self_contained render -- drop the defaults instead of failing
410 warning("Reveal plugins require self_contained: false -- ",
411 "rendering without the default plugins.",
412 call. = FALSE
413 )
414 reveal_plugins <- character(0)
415 } else {
416 stop("Using reveal_plugins requires self_contained: false")
417 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200418 }
419
JJ Allaire82a8dee2016-07-12 10:25:36 -0400420 # validate specified plugins are supported
JJ Allaire064552c2017-02-10 10:28:41 -0500421 supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu")
JJ Allaire82a8dee2016-07-12 10:25:36 -0400422 invalid_plugins <- setdiff(reveal_plugins, supported_plugins)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200423 if (length(invalid_plugins) > 0) {
JJ Allaire82a8dee2016-07-12 10:25:36 -0400424 stop("The following plugin(s) are not supported: ",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200425 paste(invalid_plugins, collapse = ", "),
426 call. = FALSE
427 )
428 }
429
JJ Allaire82a8dee2016-07-12 10:25:36 -0400430 # add plugins
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200431 if ("chalkboard" %in% reveal_plugins) {
432 # chalkboard require customcontrols so we add it to activate in the template
433 reveal_plugins <- c(reveal_plugins, "customcontrols")
434 }
JJ Allaire82a8dee2016-07-12 10:25:36 -0400435 sapply(reveal_plugins, function(plugin) {
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200436 args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin)))
437 if (plugin %in% c("customcontrols", "menu")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200438 extra_dependencies <<- append(
439 extra_dependencies,
440 list(rmarkdown::html_dependency_font_awesome())
441 )
JJ Allaire375805c2016-11-15 08:56:43 -0500442 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200443 })
JJ Allaire82a8dee2016-07-12 10:25:36 -0400444 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200445
JJ Allaire2ec40242014-09-15 09:18:39 -0400446 # content includes
447 args <- c(args, includes_to_pandoc_args(includes))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200448
JJ Allairefad55232015-10-19 07:47:26 -0400449 # additional css
christophe dervieuxf9bae672021-09-21 16:20:24 +0200450 for (css_file in css) {
JJ Allairefad55232015-10-19 07:47:26 -0400451 args <- c(args, "--css", pandoc_path_arg(css_file))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200452 }
453
JJ Allaire2ec40242014-09-15 09:18:39 -0400454 # pre-processor for arguments that may depend on the name of the
455 # the input file (e.g. ones that need to copy supporting files)
456 pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
457 output_dir) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200458
JJ Allairee60feb22016-01-30 18:28:47 -0500459 # we don't work with runtime shiny
460 if (identical(runtime, "shiny")) {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200461 stop("revealjs_presentation is not compatible with runtime 'shiny'",
462 call. = FALSE
463 )
JJ Allairee60feb22016-01-30 18:28:47 -0500464 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200465
JJ Allaire2ec40242014-09-15 09:18:39 -0400466 # use files_dir as lib_dir if not explicitly specified
christophe dervieuxf9bae672021-09-21 16:20:24 +0200467 if (is.null(lib_dir)) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400468 lib_dir <- files_dir
christophe dervieuxf9bae672021-09-21 16:20:24 +0200469 }
470
JJ Allaire2ec40242014-09-15 09:18:39 -0400471 # extra args
472 args <- c()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200473
JJ Allaire2ec40242014-09-15 09:18:39 -0400474 # reveal.js
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200475 revealjs_path <- revealjs_lib_path()
christophe dervieuxf9bae672021-09-21 16:20:24 +0200476 if (!self_contained || identical(.Platform$OS.type, "windows")) {
JJ Allaire2ec40242014-09-15 09:18:39 -0400477 revealjs_path <- relative_to(
christophe dervieuxf9bae672021-09-21 16:20:24 +0200478 output_dir, render_supporting_files(revealjs_path, lib_dir)
479 )
480 } else {
JJ Allaireeea3bca2016-07-13 12:42:01 -0400481 revealjs_path <- pandoc_path_arg(revealjs_path)
christophe dervieuxf9bae672021-09-21 16:20:24 +0200482 }
christophe dervieux062940d2021-09-21 16:26:14 +0200483 args <- c(args, pandoc_variable_arg("revealjs-url", revealjs_path))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200484
JJ Allaire2ec40242014-09-15 09:18:39 -0400485 # highlight
486 args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
christophe dervieuxf9bae672021-09-21 16:20:24 +0200487
Marc Kupietz59e95a62026-08-29 10:19:05 +0300488 # website entry: place a linked QR code (inline SVG) in the top left of
489 # the title slide
490 if (!is.null(metadata$website)) {
491 args <- c(args, pandoc_variable_arg("website-qr", qrlink(metadata$website)))
492 }
493
494 # partner / funder institution logos: local files are inlined as data
495 # URIs so they resolve correctly in CSS and stay embedded in the output
496 if (!is.null(metadata$partner_logo)) {
497 args <- c(args, pandoc_variable_arg("partner-logo-src", logo_uri(metadata$partner_logo)))
498 }
499 if (!is.null(metadata$funder_logo)) {
500 args <- c(args, pandoc_variable_arg("funder-logo-src", logo_uri(metadata$funder_logo)))
501 }
502
Marc Kupietzad0f24b2026-08-23 10:09:05 +0300503 # default to the bundled IDS citation style unless the document
504 # specifies a style of its own
505 if (is.null(metadata$csl)) {
506 args <- c(args, "--csl", pandoc_path_arg(reveal_resources("ids.csl")))
507 }
508
JJ Allaire2ec40242014-09-15 09:18:39 -0400509 # return additional args
510 args
511 }
christophe dervieuxf9bae672021-09-21 16:20:24 +0200512
Marc Kupietzb066e742026-08-23 09:57:06 +0300513 # post-processor converting <!-- MK 00:30 --> speaker timing comments into
514 # data-timing attributes on the enclosing sections (activating the pacing
515 # timer of the notes plugin) and reporting per-speaker totals
516 post_processor <- function(metadata, input_file, output_file, clean, verbose) {
517 lines <- readLines(output_file, warn = FALSE, encoding = "UTF-8")
Marc Kupietz6b65c032026-08-25 09:43:28 +0300518 lines <- merge_title_slide_notes(lines)
Marc Kupietzb066e742026-08-23 09:57:06 +0300519 result <- apply_timing_attributes(lines)
520 comments <- attr(result, "comments")
521 if (nrow(comments) > 0) {
522 result <- inject_total_time(result, sum(comments$seconds))
523 writeLines(enc2utf8(result), output_file, useBytes = TRUE)
524 message(timing_report_message(comments))
525 }
526 output_file
527 }
528
JJ Allaire2ec40242014-09-15 09:18:39 -0400529 # return format
530 output_format(
531 knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200532 pandoc = pandoc_options(
533 to = "revealjs",
christophe dervieuxad3a5752021-09-23 10:24:09 +0200534 from = from_rmarkdown(fig_caption, md_extensions),
christophe dervieuxf9bae672021-09-21 16:20:24 +0200535 args = args
536 ),
JJ Allaire2ec40242014-09-15 09:18:39 -0400537 keep_md = keep_md,
538 clean_supporting = self_contained,
Marc Kupietz725acd12026-08-28 14:03:21 +0300539 df_print = df_print,
JJ Allaire2ec40242014-09-15 09:18:39 -0400540 pre_processor = pre_processor,
Marc Kupietzb066e742026-08-23 09:57:06 +0300541 post_processor = post_processor,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200542 base_format = html_document_base(
christophe dervieux0acc6c92021-09-23 11:18:18 +0200543 lib_dir = lib_dir,
christophe dervieuxf9bae672021-09-21 16:20:24 +0200544 self_contained = self_contained,
545 mathjax = mathjax,
546 pandoc_args = pandoc_args,
547 extra_dependencies = extra_dependencies,
548 ...
549 )
550 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400551}
552
553revealjs_themes <- function() {
christophe dervieuxf9bae672021-09-21 16:20:24 +0200554 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200555 "default", # not used by reveal
Marc Kupietza737b1b2023-10-07 09:32:20 +0200556 "ids",
JJ Allaire2ec40242014-09-15 09:18:39 -0400557 "simple",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200558 "dark", # our alias for black
559 "black",
JJ Allaire2ec40242014-09-15 09:18:39 -0400560 "sky",
561 "beige",
562 "serif",
563 "solarized",
JJ Allaire2ec40242014-09-15 09:18:39 -0400564 "blood",
565 "moon",
junkka77fbf082015-03-15 22:25:47 +0100566 "night",
junkka77fbf082015-03-15 22:25:47 +0100567 "league",
christophe dervieuxf9bae672021-09-21 16:20:24 +0200568 "white"
569 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400570}
571
JJ Allaire2ec40242014-09-15 09:18:39 -0400572revealjs_transitions <- function() {
junkka77fbf082015-03-15 22:25:47 +0100573 c(
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200574 "default", # not used by reveal
575 "convex",
JJ Allaire2ec40242014-09-15 09:18:39 -0400576 "fade",
junkka77fbf082015-03-15 22:25:47 +0100577 "slide",
junkka77fbf082015-03-15 22:25:47 +0100578 "concave",
Christophe Dervieuxe1893ae2021-10-07 17:09:02 +0200579 "zoom",
580 "none"
christophe dervieuxf9bae672021-09-21 16:20:24 +0200581 )
JJ Allaire2ec40242014-09-15 09:18:39 -0400582}