Christophe Dervieux | aa008e4 | 2021-09-23 16:52:37 +0200 | [diff] [blame] | 1 | local_temp_rmd_file <- function(..., .env = parent.frame()) { |
| 2 | path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd") |
| 3 | xfun::write_utf8(c(...), path) |
| 4 | path |
| 5 | } |
| 6 | |
| 7 | local_temp_draft <- function(.env = parent.frame()) { |
| 8 | path <- withr::local_tempfile(.local_envir = .env, fileext = ".Rmd") |
| 9 | # TODO: Use `rmarkdown::draft()` when rmarkdown 2.12 is out. |
| 10 | pkg_file <- getFromNamespace("pkg_file", "rmarkdown") |
| 11 | template_path <- pkg_file("rmarkdown", "templates", "revealjs_presentation", |
| 12 | package = "revealjs") |
| 13 | rmarkdown::draft(path, template_path, edit = FALSE) |
| 14 | } |
| 15 | |
| 16 | .render_and_read <- function(input, xml = TRUE, ...) { |
| 17 | skip_if_not_pandoc() |
| 18 | output_file <- withr::local_tempfile(fileext = ".html") |
| 19 | res <- rmarkdown::render(input, output_file = output_file, quiet = TRUE, ...) |
| 20 | if (xml) { |
| 21 | xml2::read_html(res) |
| 22 | } else { |
| 23 | xfun::read_utf8(res) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | # Use to test pandoc availability or version lower than |
| 28 | skip_if_not_pandoc <- function(ver = NULL) { |
| 29 | if (!pandoc_available(ver)) { |
| 30 | msg <- if (is.null(ver)) { |
| 31 | "Pandoc is not available" |
| 32 | } else { |
| 33 | sprintf("Version of Pandoc is lower than %s.", ver) |
| 34 | } |
| 35 | skip(msg) |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | # Use to test version greater than |
| 40 | skip_if_pandoc <- function(ver = NULL) { |
| 41 | if (pandoc_available(ver)) { |
| 42 | msg <- if (is.null(ver)) { |
| 43 | "Pandoc is available" |
| 44 | } else { |
| 45 | sprintf("Version of Pandoc is greater than %s.", ver) |
| 46 | } |
| 47 | skip(msg) |
| 48 | } |
| 49 | } |