Skip to content

Commit

Permalink
Allow user to change bookdown::gitbook() options (#84)
Browse files Browse the repository at this point in the history
* Add ...

* Allow user to change "before" and "after" toc arguments

* Pass all type of option and sub-options to bookdown::gitbook
  • Loading branch information
abichat authored May 25, 2020
1 parent 352081d commit f9ee59b
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions R/thesis.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,36 @@ thesis_pdf <- function(toc = TRUE, toc_depth = 3, highlight = "default", ...){
#' }
thesis_gitbook <- function(...){

base <- bookdown::gitbook(
split_by = "chapter+number",
config = list(toc = list(collapse = "section",
before = '<li><a href="./"></a></li>',
after = '<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>',
...)
)
)
config_default <- list(
toc = list(collapse = "section",
before = '<li><a href="./"></a></li>',
after = '<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>'))

listarg <- list(...)

if (!"split_by" %in% names(listarg)) {
listarg$split_by <- "chapter+number"
}

if (!"config" %in% names(listarg)) {
listarg$config <- config_default
} else {
if (!"toc" %in% names(listarg$config)) {
listarg$config$toc <- config_default$toc
} else {
if (!"collapse" %in% names(listarg$config$toc)) {
listarg$config$toc$collapse <- config_default$toc$collapse
}
if (!"before" %in% names(listarg$config$toc)) {
listarg$config$toc$before <- config_default$toc$before
}
if (!"after" %in% names(listarg$config$toc)) {
listarg$config$toc$after <- config_default$toc$after
}
}
}

base <- do.call(bookdown::gitbook, listarg)

# Mostly copied from knitr::render_sweave
base$knitr$opts_chunk$comment <- NA
Expand Down

0 comments on commit f9ee59b

Please sign in to comment.