| Christophe Dervieux | aa008e4 | 2021-09-23 16:52:37 +0200 | [diff] [blame] | 1 | test_that("toc argument works", { |
| 2 | skip_if_not_pandoc() |
| 3 | skip_if_not_installed("xml2") |
| 4 | rmd <- local_temp_draft() |
| 5 | html <- .render_and_read( |
| 6 | rmd, |
| 7 | output_options = list( |
| 8 | toc = TRUE, |
| 9 | pandoc_args = c(pandoc_variable_arg("toc-title", "TOC")) |
| 10 | ) |
| 11 | ) |
| 12 | toc <- xml2::xml_find_all(html, "//section[@id='TOC']") |
| 13 | expect_length(toc, 1) |
| 14 | expect_equal( |
| 15 | xml2::xml_text( |
| 16 | xml2::xml_find_all(toc, "./nav/*[contains(@id, 'toc-title')]") |
| 17 | ), |
| 18 | "TOC" |
| 19 | ) |
| 20 | }) |
| Marc Kupietz | 499082c | 2026-08-30 15:26:44 +0300 | [diff] [blame] | 21 | |
| 22 | test_that("chapter_numbering option controls the numbering script", { |
| 23 | skip_if_not_pandoc() |
| 24 | rmd <- local_temp_rmd_file( |
| 25 | "---", |
| 26 | "title: 'Chapter numbering test'", |
| 27 | "output: revealjs.ids::revealjs_presentation", |
| 28 | "---", |
| 29 | "", |
| 30 | "# One", |
| 31 | "", |
| 32 | "## a", |
| 33 | "", |
| 34 | "# Two" |
| 35 | ) |
| 36 | on <- paste(.render_and_read(rmd, xml = FALSE), collapse = "\n") |
| 37 | expect_match(on, "function numberChapters", fixed = TRUE) |
| 38 | expect_match(on, "var start = 1;", fixed = TRUE) |
| 39 | |
| 40 | off <- paste(.render_and_read( |
| 41 | rmd, |
| 42 | output_options = list(chapter_numbering = FALSE), |
| 43 | xml = FALSE |
| 44 | ), collapse = "\n") |
| 45 | expect_no_match(off, "function numberChapters", fixed = TRUE) |
| 46 | |
| 47 | started <- paste(.render_and_read( |
| 48 | rmd, |
| 49 | output_options = list(chapter_numbering = 5), |
| 50 | xml = FALSE |
| 51 | ), collapse = "\n") |
| 52 | expect_match(started, "var start = 5;", fixed = TRUE) |
| 53 | |
| 54 | expect_error( |
| 55 | .render_and_read( |
| 56 | rmd, |
| 57 | output_options = list(chapter_numbering = "yes"), |
| 58 | xml = FALSE |
| 59 | ), |
| 60 | "chapter_numbering" |
| 61 | ) |
| 62 | }) |