Skip to content

Commit

Permalink
make it possible not to use the gitbook table style (rstudio#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
haozhu233 authored and yihui committed Oct 5, 2018
1 parent b6b96b6 commit e3228af
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- Added an argument `template` to `gitbook()` and `epub_book()` (thanks, @ThierryO, #570).

- Added an argument `table_css` to `gitbook()` to allow customized css for tables. (thanks, @haozhu233, #642)

## BUG FIXES

- HTML output formats such as `gitbook` and `html_document2` won't work when only unnumbered parts (i.e., `# (PART\*)`) are used (thanks, @tjmahr, #575).
Expand Down
13 changes: 9 additions & 4 deletions R/gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@
#'
#' @param config A list of configuration options for the gitbook style, such as
#' the font/theme settings.
#' @param table_css \code{TRUE} to load gitbook's default CSS for tables. Choose
#' \code{FALSE} to unload and use customized CSS (for exmaple, bootstrap) via
#' the \code{css} option. Default is \code{TRUE}.
#' @export
gitbook = function(
fig_caption = TRUE, number_sections = TRUE, self_contained = FALSE,
lib_dir = 'libs', pandoc_args = NULL, ..., template = 'default',
split_by = c('chapter', 'chapter+number', 'section', 'section+number', 'rmd', 'none'),
split_bib = TRUE, config = list()
split_bib = TRUE, config = list(), table_css = TRUE
) {
html_document2 = function(..., extra_dependencies = list()) {
rmarkdown::html_document(
..., extra_dependencies = c(extra_dependencies, gitbook_dependency())
..., extra_dependencies = c(extra_dependencies,
gitbook_dependency(table_css))
)
}
gb_config = config
Expand Down Expand Up @@ -72,15 +76,16 @@ write_search_data = function(x) {
write_utf8(x, output_path('search_index.json'))
}

gitbook_dependency = function() {
gitbook_dependency = function(table_css) {
assets = bookdown_file('resources', 'gitbook')
owd = setwd(assets); on.exit(setwd(owd), add = TRUE)
app = if (file.exists('js/app.min.js')) 'app.min.js' else 'app.js'
table_css = if (table_css) 'plugin-gitbook-table.css' else NULL
list(jquery_dependency(), htmltools::htmlDependency(
'gitbook', '2.6.7', src = assets,
stylesheet = file.path('css', c(
'style.css', 'plugin-bookdown.css', 'plugin-highlight.css',
'plugin-search.css', 'plugin-fontsettings.css'
'plugin-search.css', 'plugin-fontsettings.css', table_css
)),
script = file.path('js', c(
app, 'lunr.js', 'plugin-search.js', 'plugin-sharing.js',
Expand Down
1 change: 1 addition & 0 deletions inst/resources/gitbook/css/plugin-gitbook-table.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inst/resources/gitbook/css/style.css

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion man/gitbook.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e3228af

Please sign in to comment.