diff --git a/DESCRIPTION b/DESCRIPTION index c26af0e95..e8f8c43bc 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,8 @@ Imports: knitr (>= 1.22), rmarkdown (>= 2.3.5), xfun (>= 0.13), - tinytex (>= 0.12) + tinytex (>= 0.12), + stringr (>= 1.2.0) Suggests: htmlwidgets, rstudioapi, diff --git a/NAMESPACE b/NAMESPACE index 66150a3ce..a468c3b70 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,6 +36,7 @@ export(tufte_html_book) export(word_document2) import(stats) import(utils) +import(stringr) importFrom(xfun,in_dir) importFrom(xfun,read_utf8) importFrom(xfun,same_path) diff --git a/R/gitbook.R b/R/gitbook.R index 09fce6ca5..d269dbf34 100644 --- a/R/gitbook.R +++ b/R/gitbook.R @@ -27,7 +27,7 @@ gitbook = function( ) { html_document2 = function(..., extra_dependencies = list()) { rmarkdown::html_document( - ..., extra_dependencies = c(extra_dependencies, gitbook_dependency(table_css)) + ..., extra_dependencies = c(gitbook_dependency(table_css), extra_dependencies) ) } gb_config = config @@ -174,7 +174,46 @@ gitbook_toc = function(x, cur, config) { i2 = find_token(x, '') x[i1] = ''; x[i2] = '' if (i2 - i1 < 2) return(x) + + #Changed to allow for toc length to change over the course of the function + prior = x[1:i1] toc = x[(i1 + 1):(i2 - 1)] + post = x[i2:length(x)] + + if(is.character(rmarkdown:::yaml_load_file('_bookdown.yml')[['custom_toc']])){ + toc_frame <- readRDS("toc.Rds") + #First add in divisions and headers + for(i in (1:nrow(toc_frame))){ + if(toc_frame[i,6] == "HEADING"){ + toc <- append(toc, paste('
  • ', toc_frame[i,4], '
  • ', sep=""), i) + } else if(toc_frame[i,6] == "BREAK"){ + toc <- append(toc, '
  • ', i) + } + } + + #Check that the in length difference is due to the leading and trailing