test_that("PART feature correctly works in HTML without anchor sections", { skip_on_cran() skip_if_not_pandoc() skip_if_not_installed("xml2") rmd <- local_rmd_file(c("---", "title: test", "---", "", "# (PART) T1 {-}", "", "# CHAP1", "", "# (PART\\*) T2 {-}", "", "# CHAP2")) res <- local_render_book(rmd, output_format = gitbook(anchor_sections = FALSE)) content <- xml2::read_html(res) TOC <- xml2::xml_find_all(content, "//div[@class='book-summary']/nav/ul/li") expect_equal(xml2::xml_attr(TOC, "class"), c("part", "chapter", "part", "chapter")) expect_equal(xml2::xml_text(TOC), c("I T1", "1 CHAP1", "T2", "2 CHAP2")) }) test_that("PART feature correctly works in HTML with anchor sections", { skip_on_cran() skip_if_not_pandoc() skip_if_not_installed("xml2") rmd <- local_rmd_file(c("---", "title: test", "---", "", "# (PART) T1 {-}", "", "# CHAP1", "", "# (PART\\*) T2 {-}", "", "# CHAP2")) res <- local_render_book(rmd, output_format = gitbook(anchor_sections = TRUE)) content <- xml2::read_html(res) TOC <- xml2::xml_find_all(content, "//div[@class='book-summary']/nav/ul/li") expect_equal(xml2::xml_attr(TOC, "class"), c("part", "chapter", "part", "chapter")) expect_equal(xml2::xml_text(TOC), c("I T1", "1 CHAP1", "T2", "2 CHAP2")) }) test_that("build_404 creates correct 404 page", { skip_on_cran() skip_if_not_pandoc() tmp_dir <- withr::local_tempdir() withr::local_dir(tmp_dir) # default page expect_false(file.exists("404.html")) expect_null(build_404()$rmd_cur) expect_false(file.exists("404.html")) # custom pages xfun::write_utf8(c("# Page not found", "", "I am created with _404.Rmd"), "_404.Rmd") build_404() expect_true(file.exists("404.html")) expect_match(xfun::file_string("404.html"), "I am created with _404.Rmd", fixed = TRUE) # do nothing if one exist expect_null(build_404()$html) unlink(c("404.html", "_404.Rmd")) xfun::write_utf8(c("# Page not found", "", "I am created with _404.md"), "_404.md") build_404() expect_true(file.exists("404.html")) expect_match(xfun::file_string("404.html"), "I am created with _404.md", fixed = TRUE) }) test_that("add_toc_class() adds the class on correct toc element", { toc <- "
  • 7 Sharing your book