| 1 |
context("html_vignette format") |
| 2 |
|
| 3 |
.generate_temp_vignette <- function(title = NULL, |
| 4 |
indexentry = NULL, |
| 5 |
envir = parent.frame()) { |
| 6 |
tmp_rmd <- tempfile("vignette-", fileext = ".Rmd") |
| 7 |
xfun::write_utf8( |
| 8 |
c("---", |
| 9 |
if (!is.null(title)) sprintf("title: %s", title), |
| 10 |
"output: html_vignette", |
| 11 |
"vignette: >", |
| 12 |
if(!is.null(indexentry)) { |
| 13 |
sprintf(" %%\\VignetteIndexEntry{%s}", indexentry) |
| 14 |
}, |
| 15 |
" %\\VignetteEngine{knitr::rmarkdown}", |
| 16 |
" %\\VignetteEncoding{UTF-8}", |
| 17 |
"---", |
| 18 |
"\n# This is a vignette"), |
| 19 |
tmp_rmd) |
| 20 |
withr::defer(unlink(tmp_rmd), envir = envir) |
| 21 |
tmp_rmd |
| 22 |
} |
| 23 |
|
| 24 |
# https://github.com/rstudio/rmarkdown/pull/1789#issuecomment-616908700 |
| 25 |
test_that("vignette_pre_processor warns against differences in vignette index entry and title", { |
| 26 |
withr::local_options(list(rmarkdown.html_vignette.check_title = TRUE)) |
| 27 |
input_file <- .generate_temp_vignette('document title', 'vignette title') |
| 28 |
# only warns for R 3.6 and later |
| 29 |
if (getRversion() >= '3.6') { |
| 30 |
expect_warning(vignette_pre_processor(input_file), 'rmarkdown.html_vignette.check_title') |
| 31 |
} else { |
| 32 |
expect_null(vignette_pre_processor(input_file)) |
| 33 |
} |
| 34 |
}) |
| 35 |
|
| 36 |
# https://github.com/rstudio/rmarkdown/issues/1978 |
| 37 |
test_that("vignette_pre_processor correctly handles encoding", { |
| 38 |
withr::local_options(list(rmarkdown.html_vignette.check_title = TRUE)) |
| 39 |
input_file <- .generate_temp_vignette('Données', 'Données') |
| 40 |
expect_null(vignette_pre_processor(input_file)) |
| 41 |
}) |