| 1 |
test_that("build highlight args for pandoc correctly", { |
| 2 |
expect_equal(pandoc_highlight_args(NULL), if (pandoc_available("3.8")) c("--syntax-highlighting", "none") else "--no-highlight") |
| 3 |
expect_equal(pandoc_highlight_args("default")[2], "tango") |
| 4 |
expect_equal(pandoc_highlight_args("default", "zenburn")[2], "zenburn") |
| 5 |
expect_equal(pandoc_highlight_args("zenburn")[2], "zenburn") |
| 6 |
}) |
| 7 |
|
| 8 |
test_that("Detect if a theme file is providing in highlight", { |
| 9 |
expect_equal(resolve_highlight("default"), "default") |
| 10 |
expect_equal(resolve_highlight("breezedark"), "breezedark") |
| 11 |
expect_equal(resolve_highlight("breez"), "breezedark") |
| 12 |
expect_error(resolve_highlight("textmate"), "must be one of") |
| 13 |
expect_equal( |
| 14 |
resolve_highlight("textmate", html_highlighters()), "textmate" |
| 15 |
) |
| 16 |
if (pandoc_available("2.0")) { |
| 17 |
expect_equal(resolve_highlight("arrow"), pkg_file_highlight("arrow.theme")) |
| 18 |
expect_equal(resolve_highlight("custom.theme"), "custom.theme") |
| 19 |
expect_error(resolve_highlight("custom.json"), "a file with extension") |
| 20 |
} else { |
| 21 |
expect_error(resolve_highlight("arrow"), "requires Pandoc 2.0") |
| 22 |
} |
| 23 |
}) |
| 24 |
|
| 25 |
test_that("Correct HTML highlighting argument as requested", { |
| 26 |
# helpers |
| 27 |
hl_args <- function(highlight, template, downlit = FALSE) { |
| 28 |
pandoc_html_highlight_args(template = template, highlight = highlight, |
| 29 |
highlight_downlit = downlit) |
| 30 |
} |
| 31 |
hl_style <- pandoc_highlight_args |
| 32 |
downlit <- pandoc_variable_arg("highlight-downlit") |
| 33 |
highlightjs <- pandoc_variable_arg("highlightjs", "1") |
| 34 |
arrow_theme <- hl_style(pkg_file_highlight("arrow.theme")) |
| 35 |
rstudio_theme <- hl_style(pkg_file_highlight("rstudio.theme")) |
| 36 |
# check logic |
| 37 |
# no engine |
| 38 |
expect_equal(hl_args(NULL, "default"), hl_style(NULL)) |
| 39 |
expect_equal(hl_args(NULL, "dummy.html"), hl_style(NULL)) |
| 40 |
# pandoc |
| 41 |
expect_equal(hl_args("default", "dummy.html"), hl_style("pygments")) |
| 42 |
expect_equal(hl_args("zenburn", "dummy.html"), hl_style("zenburn")) |
| 43 |
expect_equal(hl_args("breezedark", "default"), hl_style("breezedark")) |
| 44 |
# highlight |
| 45 |
expect_equal(hl_args("default", "default"), c(hl_style(NULL), highlightjs)) |
| 46 |
expect_equal(hl_args("textmate", "default"), c(hl_style(NULL), highlightjs)) |
| 47 |
expect_error(hl_args("textmate", "dummy.html"), "Pandoc engine") |
| 48 |
# downlit |
| 49 |
expect_equal(hl_args("tango", "default", TRUE), c(hl_style("tango"), downlit)) |
| 50 |
expect_equal(hl_args("tango", "dummy.html", TRUE), c(hl_style("tango"), downlit)) |
| 51 |
expect_error(hl_args("textmate", "dummy.html", TRUE), "downlit engine") |
| 52 |
expect_error(hl_args("textmate", "default", TRUE), "downlit engine") |
| 53 |
# custom theme |
| 54 |
skip_if_not(pandoc2.0()) |
| 55 |
expect_equal(hl_args("default", "default", TRUE), c(arrow_theme, downlit)) |
| 56 |
expect_equal(hl_args("default", "dummy.html", TRUE), c(arrow_theme, downlit)) |
| 57 |
expect_equal(hl_args("arrow", "default", FALSE), c(arrow_theme)) |
| 58 |
expect_equal(hl_args("arrow", "dummy.html", FALSE), c(arrow_theme)) |
| 59 |
expect_equal(hl_args("rstudio", "default", TRUE), c(rstudio_theme, downlit)) |
| 60 |
expect_equal(hl_args("rstudio", "dummy.html", TRUE), c(rstudio_theme, downlit)) |
| 61 |
expect_equal(hl_args("path/to.theme", "default"), c(hl_style("path/to.theme"))) |
| 62 |
expect_equal(hl_args("path/to.theme", "dummy.html"), c(hl_style("path/to.theme"))) |
| 63 |
}) |
| 64 |
|
| 65 |
test_that("detect highlightjs theme", { |
| 66 |
expect_false(is_highlightjs(NULL)) |
| 67 |
expect_false(is_highlightjs("zenburn")) |
| 68 |
expect_false(is_highlightjs("path/to/hl.theme")) |
| 69 |
|
| 70 |
expect_true(is_highlightjs("default")) |
| 71 |
expect_true(is_highlightjs("textmate")) |
| 72 |
}) |
| 73 |
|
| 74 |
test_that("Converting bib file is working", { |
| 75 |
skip_on_cran() |
| 76 |
skip_if_not_pandoc("2.11") # only test with newer Pandoc citeproc |
| 77 |
skip_on_os("windows") # UTF-8 and windows does not work well for now. |
| 78 |
bib_file <- test_path("resources/UTF8.bib") |
| 79 |
expect_snapshot_value(pandoc_citeproc_convert(bib_file, "list"), style = "deparse") |
| 80 |
expect_snapshot_output(pandoc_citeproc_convert(bib_file, "json")) |
| 81 |
expect_snapshot_output(pandoc_citeproc_convert(bib_file, "yaml")) |
| 82 |
}) |
| 83 |
|
| 84 |
test_that("pandoc_math_args() build correct CLI flag", { |
| 85 |
expect_identical(pandoc_math_args("katex"), c("--katex")) |
| 86 |
expect_identical(pandoc_math_args("webtex", "url"), c("--webtex=url")) |
| 87 |
expect_error(pandoc_math_args("gladtex", "CDN"), "gladtex does not support") |
| 88 |
}) |