diff --git a/NEWS.md b/NEWS.md index a5f3d02aa..c89a03b97 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # CHANGES IN bookdown VERSION 0.15 +## BUG FIXES + +- gitbook toolbar is not missing any more when rendering books with Pandoc 2.x and using `self_contained = TRUE` (thanks, @Pindar777, @RLesur, @cderv, #739). # CHANGES IN bookdown VERSION 0.14 diff --git a/R/gitbook.R b/R/gitbook.R index e19b518be..58d1f7b5b 100644 --- a/R/gitbook.R +++ b/R/gitbook.R @@ -130,10 +130,17 @@ gitbook_page = function( # gitbook JS scripts only work after the DOM has been loaded, so move them # from head to foot i = grep('^\\s*\\s*$', head) - # it is probably a self-contained page, so look for base64 encoded scripts - if (length(i) == 0) i = grep( - '^\\s*\\s*$', head - ) + # it is probably a self-contained page, so look for script node. + # from pandoc2, they are not always base64 encoded scripts, so start and end of scripts + # node must be found and moved. + if (length(i) == 0) { + s_start = grep( + '^\\s*', head + ) + s_end = grep("\\s*$", head) + # find all lines to move + i = unlist(mapply(seq.int, s_start, s_end, SIMPLIFY = FALSE)) + } s = head[i]; head[i] = '' j = grep('', foot)[1] foot[j] = paste(c(s, foot[j]), collapse = '\n')