| 1 |
test_that("toc has correct identifier", { |
| 2 |
skip_on_cran() # avoid pandoc issue on CRAN |
| 3 |
skip_if_not_pandoc("2.10.1") # changes in gfm writer break this test for earlier versions |
| 4 |
tmp_file <- local_rmd_file( |
| 5 |
c("# 10 Section","","Sentence.","", "# Header","","Sentence ") |
| 6 |
) |
| 7 |
pandoc_version <- if (pandoc_available("3")) { |
| 8 |
"pandoc-3" |
| 9 |
} else if (pandoc_available("2.18.0.1")) { |
| 10 |
"after-pandoc-2.18" |
| 11 |
} else if (pandoc_available("2.18")) { |
| 12 |
"pandoc-2.18" |
| 13 |
} else { |
| 14 |
"before-pandoc-2.18" |
| 15 |
} |
| 16 |
res <- render(tmp_file, github_document(toc = TRUE, html_preview = FALSE), quiet = TRUE) |
| 17 |
expect_snapshot_file(res, "github-toc.md", compare = compare_file_text, variant = pandoc_version) |
| 18 |
}) |
| 19 |
|
| 20 |
test_that("toc has correct identifier also when sections are numbered ", { |
| 21 |
skip_on_cran() # avoid pandoc issue on CRAN |
| 22 |
skip_if_not_pandoc("2.10.1") # changes in gfm writer break this test for earlier versions |
| 23 |
tmp_file <- local_rmd_file( |
| 24 |
c("# Section","","Sentence.","", "# Header","","Sentence ") |
| 25 |
) |
| 26 |
pandoc_version <- if (pandoc_available("3")) { |
| 27 |
"pandoc-3" |
| 28 |
} else if (pandoc_available("2.18.0.1")) { |
| 29 |
"after-pandoc-2.18" |
| 30 |
} else if (pandoc_available("2.18")) { |
| 31 |
"pandoc-2.18" |
| 32 |
} else { |
| 33 |
"before-pandoc-2.18" |
| 34 |
} |
| 35 |
res <- render(tmp_file, github_document(toc = TRUE, number_sections = TRUE, html_preview = FALSE), quiet = TRUE) |
| 36 |
expect_snapshot_file(res, "github-toc-numbered.md", compare = compare_file_text, variant = pandoc_version) |
| 37 |
}) |
| 38 |
|
| 39 |
|
| 40 |
test_that("github_document produces atx-header", { |
| 41 |
skip_on_cran() # avoid pandoc issue on CRAN |
| 42 |
h <- paste0(Reduce(paste0, rep("#", 5), accumulate = TRUE), " title ", 1:5, "\n\n") |
| 43 |
tmp_file <- local_rmd_file(h) |
| 44 |
res <- render(tmp_file, github_document(html_preview = FALSE), quiet = TRUE) |
| 45 |
expect_snapshot_file(res, "github-atx.md", compare = compare_file_text) |
| 46 |
}) |
| 47 |
|
| 48 |
test_that("github_document supports native math", { |
| 49 |
skip_on_cran() |
| 50 |
skip_if_not_pandoc("2.10.1") |
| 51 |
tmp_file <- local_rmd_file(c( |
| 52 |
"**The Cauchy-Schwarz Inequality**", |
| 53 |
"$$\\sum_{k=1}^n$$", |
| 54 |
"", |
| 55 |
"This sentence uses `$` delimiters to show math inline: $\\sqrt{3x-1}+(1+x)^2$" |
| 56 |
)) |
| 57 |
res <- .render_and_read(tmp_file, output_format = github_document(html_preview = FALSE)) |
| 58 |
expect_match(res, "$$\\sum_{k=1}^n$$", fixed = TRUE, all = FALSE) |
| 59 |
expect_match(res, "$\\sqrt{3x-1}+(1+x)^2$", fixed = TRUE, all = FALSE) |
| 60 |
}) |
| 61 |
|
| 62 |
test_that("github_document supports math with webtex", { |
| 63 |
skip_on_cran() |
| 64 |
skip_if_not_pandoc("2.0.4") |
| 65 |
skip_if_offline("latex.codecogs.com") |
| 66 |
tmp_file <- local_rmd_file(c( |
| 67 |
"**The Cauchy-Schwarz Inequality**", |
| 68 |
"$$\\sum_{k=1}^n$$", |
| 69 |
"", |
| 70 |
"This sentence uses `$` delimiters to show math inline: $\\sqrt{3x-1}+(1+x)^2$" |
| 71 |
)) |
| 72 |
res <- .render_and_read(tmp_file, output_format = github_document(html_preview = FALSE, math_method = "webtex")) |
| 73 |
expect_match(res, "^!\\[.*][(]https://latex[.]codecogs[.]com", all = FALSE) |
| 74 |
}) |
| 75 |
|
| 76 |
test_that("github_document uses webtex as default for pandoc before 2.10.1", { |
| 77 |
skip_on_cran() |
| 78 |
skip_if_pandoc("2.10.1") |
| 79 |
skip_if_not_pandoc("2.0.4") |
| 80 |
skip_if_offline("latex.codecogs.com") |
| 81 |
tmp_file <- local_rmd_file(c( |
| 82 |
"**The Cauchy-Schwarz Inequality**", |
| 83 |
"$$\\sum_{k=1}^n$$", |
| 84 |
"", |
| 85 |
"This sentence uses `$` delimiters to show math inline: $\\sqrt{3x-1}+(1+x)^2$" |
| 86 |
)) |
| 87 |
res <- .render_and_read(tmp_file, output_format = github_document(html_preview = FALSE, math_method = "default")) |
| 88 |
expect_match(res, "^!\\[.*][(]https://latex[.]codecogs[.]com", all = FALSE) |
| 89 |
}) |