Style with styler
diff --git a/R/revealjs_presentation.R b/R/revealjs_presentation.R
index d6d3d7d..b345c51 100644
--- a/R/revealjs_presentation.R
+++ b/R/revealjs_presentation.R
@@ -1,69 +1,68 @@
#' Convert to a reveal.js presentation
-#'
+#'
#' Format for converting from R Markdown to a reveal.js presentation.
-#'
+#'
#' @inheritParams rmarkdown::beamer_presentation
#' @inheritParams rmarkdown::pdf_document
#' @inheritParams rmarkdown::html_document
-#'
+#'
#' @param smart Produce typographically correct output, converting straight
#' quotes to curly quotes, \code{---} to em-dashes, \code{--} to en-dashes, and
#' \code{...} to ellipses.
#' @param center \code{TRUE} to vertically center content on slides
-#' @param slide_level Level of heading to denote individual slides. If
-#' \code{slide_level} is 2 (the default), a two-dimensional layout will be
-#' produced, with level 1 headers building horizontally and level 2 headers
-#' building vertically. It is not recommended that you use deeper nesting of
+#' @param slide_level Level of heading to denote individual slides. If
+#' \code{slide_level} is 2 (the default), a two-dimensional layout will be
+#' produced, with level 1 headers building horizontally and level 2 headers
+#' building vertically. It is not recommended that you use deeper nesting of
#' section levels with reveal.js.
-#' @param theme Visual theme ("simple", "sky", "beige", "serif", "solarized",
+#' @param theme Visual theme ("simple", "sky", "beige", "serif", "solarized",
#' "blood", "moon", "night", "black", "league" or "white").
-#' @param transition Slide transition ("default", "none", "fade", "slide",
+#' @param transition Slide transition ("default", "none", "fade", "slide",
#' "convex", "concave" or "zoom")
-#' @param background_transition Slide background-transition ("default", "none",
+#' @param background_transition Slide background-transition ("default", "none",
#' "fade", "slide", "convex", "concave" or "zoom")
-#' @param reveal_options Additional options to specify for reveal.js (see
+#' @param reveal_options Additional options to specify for reveal.js (see
#' \href{https://revealjs.com/config/}{https://revealjs.com/config/}
#' for details).
#' @param reveal_plugins Reveal plugins to include. Available plugins include
#' "notes", "search", "zoom", "chalkboard", and "menu". Note that
#' \code{self_contained} must be set to \code{FALSE} in order to use Reveal
#' plugins.
-#' @param template Pandoc template to use for rendering. Pass "default" to use
-#' the rmarkdown package default template; pass \code{NULL} to use pandoc's
-#' built-in template; pass a path to use a custom template that you've
-#' created. Note that if you don't use the "default" template then some
-#' features of \code{revealjs_presentation} won't be available (see the
+#' @param template Pandoc template to use for rendering. Pass "default" to use
+#' the rmarkdown package default template; pass \code{NULL} to use pandoc's
+#' built-in template; pass a path to use a custom template that you've
+#' created. Note that if you don't use the "default" template then some
+#' features of \code{revealjs_presentation} won't be available (see the
#' Templates section below for more details).
#' @param extra_dependencies Additional function arguments to pass to the base R
#' Markdown HTML output formatter [rmarkdown::html_document_base()].
#' @param ... Ignored
-#'
+#'
#' @return R Markdown output format to pass to \code{\link{render}}
-#'
+#'
#' @details
-#'
+#'
#' In reveal.js presentations you can use level 1 or level 2 headers for slides.
#' If you use a mix of level 1 and level 2 headers then a two-dimensional layout
-#' will be produced, with level 1 headers building horizontally and level 2
+#' will be produced, with level 1 headers building horizontally and level 2
#' headers building vertically.
-#'
-#' For additional documentation on using revealjs presentations see
+#'
+#' For additional documentation on using revealjs presentations see
#' \href{https://github.com/rstudio/revealjs}{https://github.com/rstudio/revealjs}.
-#'
+#'
#' @examples
#' \dontrun{
-#'
+#'
#' library(rmarkdown)
#' library(revealjs)
-#'
+#'
#' # simple invocation
#' render("pres.Rmd", revealjs_presentation())
-#'
+#'
#' # specify an option for incremental rendering
#' render("pres.Rmd", revealjs_presentation(incremental = TRUE))
#' }
-#'
-#'
+#'
#' @export
revealjs_presentation <- function(incremental = FALSE,
center = FALSE,
@@ -90,10 +89,10 @@
extra_dependencies = NULL,
md_extensions = NULL,
...) {
-
+
# base pandoc options for all reveal.js output
args <- c()
-
+
# template path and assets
if (identical(template, "default")) {
default_template <- reveal_resources("default.html")
@@ -101,42 +100,42 @@
} else if (!is.null(template)) {
args <- c(args, "--template", pandoc_path_arg(template))
}
-
+
# incremental
- if (incremental)
- args <- c(args, "--incremental")
-
+ if (incremental) args <- c(args, "--incremental")
+
# centering
args <- c(args, pandoc_variable_arg("center", jsbool(center)))
-
+
# slide level
args <- c(args, "--slide-level", as.character(slide_level))
-
+
# theme
theme <- match.arg(theme, revealjs_themes())
- if (identical(theme, "default"))
+ if (identical(theme, "default")) {
theme <- "simple"
- else if (identical(theme, "dark"))
+ } else if (identical(theme, "dark")) {
theme <- "black"
- if (theme %in% c("blood", "moon", "night", "black"))
+ }
+ if (theme %in% c("blood", "moon", "night", "black")) {
args <- c(args, "--variable", "theme-dark")
- args <- c(args, "--variable", paste("theme=", theme, sep=""))
-
-
+ }
+ args <- c(args, "--variable", paste("theme=", theme, sep = ""))
+
+
# transition
transition <- match.arg(transition, revealjs_transitions())
- args <- c(args, "--variable", paste("transition=", transition, sep=""))
-
+ args <- c(args, "--variable", paste("transition=", transition, sep = ""))
+
# background_transition
background_transition <- match.arg(background_transition, revealjs_transitions())
- args <- c(args, "--variable", paste("backgroundTransition=", background_transition, sep=""))
-
+ args <- c(args, "--variable", paste("backgroundTransition=", background_transition, sep = ""))
+
# use history
args <- c(args, pandoc_variable_arg("history", "true"))
-
+
# additional reveal options
if (is.list(reveal_options)) {
-
add_reveal_option <- function(option, value) {
if (is.logical(value)) {
value <- jsbool(value)
@@ -144,26 +143,28 @@
# Special handling for some chalkboard plugin options
# e.g: color: [ 'rgba(0,0,255,1)', 'rgba(255,255,255,0.5)' ]
if (grepl("chalkboard-(background|color|draw|pen)", option)) {
- value <- sprintf('[%s]', paste(paste0("'", value, "'"), collapse = ", "))
+ value <- sprintf("[%s]", paste(paste0("'", value, "'"), collapse = ", "))
}
# Add quotes around some config that can be several type
# like number or percent unit or slideNumber = true or slideNumber = 'c/t'
if (
option %in% c("slideNumber") ||
- (option %in% c("width", "height") && grepl("%$", value))) {
+ (option %in% c("width", "height") && grepl("%$", value))) {
value <- paste0("'", value, "'")
}
}
args <<- c(args, pandoc_variable_arg(option, value))
}
-
+
for (option in names(reveal_options)) {
# special handling for nested options
if (option %in% c("chalkboard", "menu")) {
nested_options <- reveal_options[[option]]
for (nested_option in names(nested_options)) {
- add_reveal_option(paste0(option, "-", nested_option),
- nested_options[[nested_option]])
+ add_reveal_option(
+ paste0(option, "-", nested_option),
+ nested_options[[nested_option]]
+ )
}
}
# standard top-level options
@@ -172,95 +173,111 @@
}
}
}
-
+
# reveal plugins
if (is.character(reveal_plugins)) {
-
+
# validate that we need to use self_contained for plugins
- if (self_contained)
+ if (self_contained) {
stop("Using reveal_plugins requires self_contained: false")
-
+ }
+
# validate specified plugins are supported
supported_plugins <- c("notes", "search", "zoom", "chalkboard", "menu")
invalid_plugins <- setdiff(reveal_plugins, supported_plugins)
- if (length(invalid_plugins) > 0)
+ if (length(invalid_plugins) > 0) {
stop("The following plugin(s) are not supported: ",
- paste(invalid_plugins, collapse = ", "), call. = FALSE)
-
+ paste(invalid_plugins, collapse = ", "),
+ call. = FALSE
+ )
+ }
+
# add plugins
sapply(reveal_plugins, function(plugin) {
args <<- c(args, pandoc_variable_arg(paste0("plugin-", plugin), "1"))
if (plugin %in% c("chalkboard", "menu")) {
- extra_dependencies <<- append(extra_dependencies,
- list(rmarkdown::html_dependency_font_awesome()))
-
+ extra_dependencies <<- append(
+ extra_dependencies,
+ list(rmarkdown::html_dependency_font_awesome())
+ )
}
- })
+ })
}
-
+
# content includes
args <- c(args, includes_to_pandoc_args(includes))
-
+
# additional css
- for (css_file in css)
+ for (css_file in css) {
args <- c(args, "--css", pandoc_path_arg(css_file))
-
+ }
+
# pre-processor for arguments that may depend on the name of the
# the input file (e.g. ones that need to copy supporting files)
pre_processor <- function(metadata, input_file, runtime, knit_meta, files_dir,
output_dir) {
-
+
# we don't work with runtime shiny
if (identical(runtime, "shiny")) {
- stop("revealjs_presentation is not compatible with runtime 'shiny'",
- call. = FALSE)
+ stop("revealjs_presentation is not compatible with runtime 'shiny'",
+ call. = FALSE
+ )
}
-
+
# use files_dir as lib_dir if not explicitly specified
- if (is.null(lib_dir))
+ if (is.null(lib_dir)) {
lib_dir <- files_dir
-
+ }
+
# extra args
args <- c()
-
+
# reveal.js
revealjs_path <- system.file("reveal.js-3.3.0.1", package = "revealjs")
- if (!self_contained || identical(.Platform$OS.type, "windows"))
+ if (!self_contained || identical(.Platform$OS.type, "windows")) {
revealjs_path <- relative_to(
- output_dir, render_supporting_files(revealjs_path, lib_dir))
- else
+ output_dir, render_supporting_files(revealjs_path, lib_dir)
+ )
+ } else {
revealjs_path <- pandoc_path_arg(revealjs_path)
+ }
args <- c(args, "--variable", paste0("revealjs-url=", revealjs_path))
-
+
# highlight
args <- c(args, pandoc_highlight_args(highlight, default = "pygments"))
-
+
# return additional args
args
}
-
+
# return format
output_format(
knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md),
- pandoc = pandoc_options(to = "revealjs",
- from = rmarkdown_format(paste0(
- md_extensions,
- ifelse(fig_caption, "", "-implicit_figures")
- )),
- args = args),
+ pandoc = pandoc_options(
+ to = "revealjs",
+ from = rmarkdown_format(paste0(
+ md_extensions,
+ ifelse(fig_caption, "", "-implicit_figures")
+ )),
+ args = args
+ ),
keep_md = keep_md,
clean_supporting = self_contained,
pre_processor = pre_processor,
- base_format = html_document_base(smart = smart, lib_dir = lib_dir,
- self_contained = self_contained,
- mathjax = mathjax,
- pandoc_args = pandoc_args,
- extra_dependencies = extra_dependencies,
- ...))
+ base_format = html_document_base(
+ smart = smart, lib_dir = lib_dir,
+ self_contained = self_contained,
+ mathjax = mathjax,
+ pandoc_args = pandoc_args,
+ extra_dependencies = extra_dependencies,
+ ...
+ )
+ )
}
revealjs_themes <- function() {
- c("default",
+ c(
+ "default",
"dark",
"simple",
"sky",
@@ -272,7 +289,8 @@
"night",
"black",
"league",
- "white")
+ "white"
+ )
}
@@ -285,7 +303,5 @@
"convex",
"concave",
"zoom"
- )
+ )
}
-
-