christophe dervieux | 92fa469 | 2021-09-21 16:15:17 +0200 | [diff] [blame] | 1 | # function to lookup reveal resource |
| 2 | reveal_resources <- function(...) { |
| 3 | system.file("rmarkdown/templates/revealjs_presentation/resources", |
| 4 | ..., |
| 5 | package = "revealjs") |
christophe dervieux | 24418a8 | 2021-09-21 16:17:18 +0200 | [diff] [blame] | 6 | } |
| 7 | |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 8 | |
| 9 | revealjs_lib_path <- function(...) { |
| 10 | pkg <- system.file(package = "revealjs") |
| 11 | lib_folder <- list.files(pkg, pattern = "reveal.js-")[1] |
| 12 | system.file(lib_folder, ..., package = "revealjs") |
| 13 | } |
| 14 | |
| 15 | revealjs_version <- function() { |
| 16 | as.numeric_version(gsub(".*reveal\\.js-(.*)$", "\\1", revealjs_lib_path())) |
| 17 | } |
| 18 | |
christophe dervieux | 24418a8 | 2021-09-21 16:17:18 +0200 | [diff] [blame] | 19 | # Convert boolean from R to JS boolean |
Christophe Dervieux | 2f01dc9 | 2021-09-22 09:37:18 +0200 | [diff] [blame] | 20 | jsbool <- function(value) ifelse(value, "true", "false") |
| 21 | |
| 22 | # transfrom reveal option as pandoc variable |
| 23 | process_reveal_option <- function(option, value) { |
| 24 | if (is.logical(value)) { |
| 25 | value <- jsbool(value) |
| 26 | } else if (is.character(value)) { |
Christophe Dervieux | e1893ae | 2021-10-07 17:09:02 +0200 | [diff] [blame] | 27 | # Special handling for some vector options |
| 28 | if ( |
| 29 | # chalkboard plugin options |
| 30 | # e.g: color: [ 'rgba(0,0,255,1)', 'rgba(255,255,255,0.5)' ] |
| 31 | grepl("chalkboard-(background|draw)", option) |
| 32 | # e.g autoAnimateStyles: ['opacity','color'] |
| 33 | || grepl("autoAnimateStyles", option) |
| 34 | ) { |
| 35 | if (length(value) > 1 || !grepl("^\\[.*\\]$", value)) { |
| 36 | value <- sprintf("[%s]", paste(paste0("'", value, "'"), collapse = ", ")) |
| 37 | } |
Christophe Dervieux | 2f01dc9 | 2021-09-22 09:37:18 +0200 | [diff] [blame] | 38 | } |
| 39 | # Add quotes around some config that can be several type |
| 40 | # like number or percent unit or slideNumber = true or slideNumber = 'c/t' |
| 41 | if ( |
| 42 | option %in% c("slideNumber") || |
| 43 | (option %in% c("width", "height") && grepl("%$", value))) { |
| 44 | value <- paste0("'", value, "'") |
| 45 | } |
| 46 | } |
| 47 | pandoc_variable_arg(option, value) |
Christophe Dervieux | aa008e4 | 2021-09-23 16:52:37 +0200 | [diff] [blame] | 48 | } |