Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra_dependencies handling in gitbook() #1408

Merged
merged 4 commits into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bookdown
Type: Package
Title: Authoring Books and Technical Documents with R Markdown
Version: 0.32.1
Version: 0.32.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("JJ", "Allaire", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# CHANGES IN bookdown VERSION 0.33

- `extra_dependencies` in `gitbook()` is now correctly working (thanks, @ThierryO, #1408).

# CHANGES IN bookdown VERSION 0.32

- The defunct `kindlegen()` has been removed from this package.
Expand Down
2 changes: 1 addition & 1 deletion R/gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ gitbook = function(
config = html_document2(
toc = TRUE, number_sections = number_sections, fig_caption = fig_caption,
self_contained = self_contained, anchor_sections = anchor_sections,
lib_dir = lib_dir, theme = NULL,
lib_dir = lib_dir, theme = NULL, extra_dependencies = extra_dependencies,
template = template, pandoc_args = pandoc_args2(pandoc_args), ...
)
config$pandoc$lua_filters = append(config$pandoc$lua_filters, lua_filters)
Expand Down
11 changes: 4 additions & 7 deletions tests/testthat/helper-bs4_book.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ local_bs4_book <- function(name = "book",
path <- local_book(name = name, title = title, author = author,
description = description, url = url, verbose = verbose, env = env)

suppressMessages(
render_book(
path,
output_format = "bookdown::bs4_book",
output_options = output_options,
quiet = TRUE
)
.render_book_quiet(
path,
output_format = "bookdown::bs4_book",
output_options = output_options,
)

return(path)
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ local_book <- function(name = "book",

return(path)
}

.render_book_quiet <- function(...) {
suppressMessages(render_book(..., quiet = TRUE))
}
4 changes: 2 additions & 2 deletions tests/testthat/test-bs4_book.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,13 @@ test_that("bs4_book() and 404 -- custom 404 page", {
book <- local_bs4_book()
withr::local_dir(book)
xfun::write_utf8(c("# Page not found", "", "I am created with _404.Rmd"), "_404.Rmd")
suppressMessages(render_book(".", "bookdown::bs4_book", quiet = TRUE))
.render_book_quiet(".", "bookdown::bs4_book")
expect_true(file.exists("_book/404.html"))
html <- xml2::read_html("_book/404.html")
expect_match(xml2::xml_text(xml2::xml_find_first(html, ".//main/div/p")), "_404.Rmd", fixed = TRUE)
unlink("_404.Rmd")
xfun::write_utf8(c("# Page not found", "", "I am created with _404.md"), "_404.md")
suppressMessages(render_book(".", "bookdown::bs4_book", quiet = TRUE))
.render_book_quiet(".", "bookdown::bs4_book")
expect_true(file.exists("_book/404.html"))
html <- xml2::read_html("_book/404.html")
expect_match(xml2::xml_text(xml2::xml_find_first(html, ".//main/div/p")), "_404.md", fixed = TRUE)
Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ test_that("gitbook_toc correctly process pandoc html with anchor section", {
# no empty spans https://github.com/rstudio/bookdown/issues/1326
expect_true(all(xml2::xml_find_lgl(TOC, "not(boolean(./a/span[count(node()) = 0]))")))
})

# https://github.com/rstudio/bookdown/pull/1408
# https://github.com/rstudio/bookdown/issues/1101
test_that("gitbook() correctly handles extra_dependency after its own", {
skip_on_cran()
skip_if_not_pandoc()
skip_if_not_installed("xml2")
book <- local_book()
res <- .render_book_quiet(
book,
output_format = gitbook(extra_dependencies = list(rmarkdown::html_dependency_font_awesome())),
)
content <- xml2::read_html(res)
gitbook_css <- xml2::xml_find_first(content, "//head/link[contains(@href, 'gitbook')][last()]")
extra_css <- xml2::xml_find_all(gitbook_css, "./following-sibling::link[contains(@href, 'font-awesome')]")
expect_gt(length(extra_css), 0L)
})
4 changes: 2 additions & 2 deletions tests/testthat/test-skeleton.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test_that("Created gitbook template works", {
skip_if_not_pandoc()
dir <- withr::local_tempdir()
create_gitbook(dir)
expect_error(suppressMessages(render_book(dir, quiet = TRUE)), NA)
expect_error(.render_book_quiet(dir), NA)
})

test_that("Created bs4_book template works", {
Expand All @@ -69,6 +69,6 @@ test_that("Created bs4_book template works", {
skip_if_bs4_book_deps_missing()
dir <- withr::local_tempdir()
create_bs4_book(dir)
res <- suppressMessages(render_book(dir, new_session = FALSE, quiet = TRUE))
res <- .render_book_quiet(dir, new_session = FALSE)
expect_true(file.exists(res))
})