Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
2059192
wip support for Bootstrap 4 with backwards-compatibility
cpsievert Nov 21, 2019
c8c4b78
get .tabset-dropdown working in strict BS4 mode
cpsievert Nov 22, 2019
1f65638
tabset-dropdown shouldn't be opinionated about it's background
cpsievert Nov 22, 2019
eb7c3a2
helper function for normailizing the theme name
cpsievert Nov 22, 2019
4489bb3
precisely measure navbar height for all bootswatch themes
cpsievert Nov 22, 2019
7bb9d34
Improve documentation
cpsievert Nov 22, 2019
f5eb9af
cleanup
cpsievert Nov 22, 2019
d73bad7
helper to normalize bootstrap version
cpsievert Nov 22, 2019
0fabaa3
Default to a base font size of 14px (instead of 16px)
cpsievert Nov 22, 2019
0787f7d
Fix header alignment of pandoc tables in bs4
cpsievert Nov 22, 2019
173ac60
make the navbar expand breakpoint configurable
cpsievert Nov 22, 2019
3e1abaa
bootscss -> bootsass
cpsievert Nov 22, 2019
417b813
don't overwrite the same var in codefolding logic
cpsievert Nov 25, 2019
0fec280
Use master branch of bootsass
cpsievert Nov 25, 2019
d46485f
Make sure we match on major version 4 and not other versions that sta…
cpsievert Nov 25, 2019
7db2966
Use new bootswatch_theme_navbar_height() function
cpsievert Nov 25, 2019
da93a2c
merge with master
cpsievert Nov 26, 2019
0e0c065
normalize bootstrap_version in relevant exported functions
cpsievert Nov 26, 2019
3a5bae6
maintain backwards compatibility of html_dependency_bootstrap()
cpsievert Nov 26, 2019
11980fe
Set font-size-base default as part of a theme object and apply the us…
cpsievert Nov 26, 2019
82c553e
use newly renamed navbar_height() function
cpsievert Nov 26, 2019
989bc53
decouple tabset-dropdown's active class from Bootstrap's active class…
cpsievert Nov 26, 2019
8112ba7
only apply nav-item class to non-dropdowns
cpsievert Nov 26, 2019
87f8b0f
make h1.title a bit bigger than h1
cpsievert Nov 27, 2019
69161c1
Use BS3's margin-top header setting in BS4
cpsievert Nov 27, 2019
c74271d
Merge branch 'master' into carson/feature/bs4
cpsievert Nov 29, 2019
751149d
Package renamed to bootstraplib
cpsievert Dec 2, 2019
d979e87
update to latest version of bootstraplib
cpsievert Dec 4, 2019
c0c4f36
If theme is not a string, consider it to be arbitrary SASS input
cpsievert Dec 9, 2019
96661b7
bs4 pandoc var shouldn't be necessary
cpsievert Dec 9, 2019
650053a
avoid bootstraplib functions when version is 3
cpsievert Dec 9, 2019
832be83
In BS4, theme can be an empty string, which means vanilla Bootstrap
cpsievert Dec 9, 2019
564ee33
Merge branch 'master' into carson/feature/bs4
cpsievert Dec 10, 2019
2f04918
merge with master
cpsievert Dec 11, 2019
8a6cd0a
Merge branch 'master' into carson/feature/bs4
cpsievert Dec 16, 2019
21d9da6
Fix bootswatch theme listing in docs
cpsievert Dec 18, 2019
e80f395
Temporarily set the bootswatch.theme option during rendering of html_…
cpsievert Dec 18, 2019
e88423b
use new offical api for setting/clearing bootstraplib themes
cpsievert Dec 19, 2019
e1cfbb8
Don't bump jquery unless we need to
cpsievert Dec 19, 2019
9b3189d
Use latest bootstraplib functions
cpsievert Dec 20, 2019
ec69baf
Use latest bootstraplib API, minimize new code paths
cpsievert Jan 6, 2020
c1c4f3f
Don't set a new theme if theme is NULL
cpsievert Jan 6, 2020
b3e8c49
update docs
cpsievert Jan 6, 2020
4dffce0
Calling bs_theme_new() is only necessary for BS4
cpsievert Jan 10, 2020
2abf5a5
merge with master
cpsievert Jan 15, 2020
06ae110
Merge branch 'master' into carson/feature/bs4
cpsievert Jan 21, 2020
9a2d2c7
Use BS3 Sass if user has added to the theme
cpsievert Jan 24, 2020
d587b7b
bootstraplib now wants 4+3 instead of 4-3
cpsievert Feb 5, 2020
7dc7aeb
Merge branch 'master' into carson/feature/bs4
cpsievert Feb 18, 2020
720fbd2
Merge branch 'master' into carson/feature/bs4
cpsievert Apr 17, 2020
310fbeb
bump version
cpsievert Apr 17, 2020
b79fb4d
Merge branch 'master' into carson/feature/bs4
cpsievert Jun 22, 2020
b9f0b68
Merge branch 'master' into carson/feature/bs4
cpsievert Oct 6, 2020
03e2ff6
Remove bootstrap_version and allow theme to be a list of bs_theme() p…
cpsievert Oct 7, 2020
8ad4c5a
Cleanup global theme management logic
cpsievert Oct 7, 2020
fa0afa9
Minimize differences from existing logic
cpsievert Oct 7, 2020
c2b2b58
fix appending logic
cpsievert Oct 7, 2020
c1feb1f
provide files_dir attribute
Oct 7, 2020
d58d57c
normalize the path and recheck if it exists (this may fix a weird pro…
yihui Oct 8, 2020
a4d03ec
Merge branch 'master' into carson/feature/bs4
cpsievert Oct 9, 2020
3b171fb
bs_dependencies() has changed to bs_theme_dependencies()
cpsievert Oct 13, 2020
8a23b75
Add dynamic theming support to shiny runtime docs & allow theme arg t…
cpsievert Oct 29, 2020
6e45e4e
Merge branch 'master' into carson/feature/bs4
cpsievert Oct 29, 2020
27bbe8b
bump version
cpsievert Oct 29, 2020
00cab01
rename bootstraplib package to bslib
cpsievert Nov 4, 2020
28a1de4
Use output_format_from_yaml_front_matter() to get the theme from the …
cpsievert Nov 9, 2020
ea261c0
Merge branch 'master' into carson/feature/bs4
cpsievert Nov 25, 2020
3b165a1
Include header sizing/margins with html_dependency_bootstrap()
cpsievert Dec 3, 2020
178d43e
Merge branch 'master' into carson/feature/bs4
cpsievert Jan 8, 2021
208751e
Check shiny version when bslib is used with runtime: shiny
cpsievert Jan 8, 2021
8f45ae2
Fix NEWS conflict
cpsievert Jan 18, 2021
017a6e7
Remove non-glyphicon implementation of tabset-dropdown
cpsievert Jan 18, 2021
8db1743
Remove changes to tabsets.js and just rely on bs3compat for bs4 nav s…
cpsievert Jan 18, 2021
c1ec403
Don't do anything BS4-specific with navbars
cpsievert Jan 18, 2021
c532ab1
Revert to BS3 navbar markup -- we could/should provide more 'native' …
cpsievert Jan 18, 2021
861fbd3
keep minimizing code changes
cpsievert Jan 18, 2021
26157b0
Allow css parameter to understand .scss/.sass extensions
cpsievert Jan 18, 2021
923cd36
Slightly less navbar padding
cpsievert Jan 18, 2021
36f6803
Yank problematic hard coded colors out of template and ship with stat…
cpsievert Jan 18, 2021
f73c1f2
Fix theme_version() bug
cpsievert Jan 18, 2021
e0e6f22
Slightly better :hover color on dropdown-submenu link
cpsievert Jan 18, 2021
c2cb8b2
Build man/, add sass to suggests
cpsievert Jan 19, 2021
cd331e9
Apply suggestions from code review
cpsievert Jan 19, 2021
7982cb6
Use resolve_theme() to centralize theme value checks
cpsievert Jan 19, 2021
9cb2f77
Build man/
cpsievert Jan 19, 2021
1f40974
Better comment
cpsievert Jan 19, 2021
90fe45d
Merge branch 'master' into carson/feature/bs4
cpsievert Jan 19, 2021
65579f4
Bump dev version
cpsievert Jan 20, 2021
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
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rmarkdown
Type: Package
Title: Dynamic Documents for R
Version: 2.6.5
Version: 2.6.6
Authors@R: c(
person("JJ", "Allaire", role = "aut", email = "[email protected]"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand All @@ -20,6 +20,7 @@ Authors@R: c(
comment = c(ORCID = "0000-0002-8335-495X",
cph = "Number sections Lua filter")),
person("Barret", "Schloerke", role = "ctb"),
person("Carson", "Sievert", role = "ctb", comment = c(ORCID = "0000-0002-4958-2844")),
person("Christophe", "Dervieux", role = "ctb"),
person("Frederik", "Aust", role = "ctb", email = "[email protected]", comment = c(ORCID = "0000-0003-4900-788X")),
person("Jeff", "Allen", role = "ctb", email = "[email protected]"),
Expand Down Expand Up @@ -102,11 +103,14 @@ Suggests:
tibble,
fs,
rsconnect,
withr (>= 2.3.0)
withr (>= 2.3.0),
bslib,
sass
SystemRequirements: pandoc (>= 1.14) - http://pandoc.org
URL: https://github.com/rstudio/rmarkdown
BugReports: https://github.com/rstudio/rmarkdown/issues
License: GPL-3
RoxygenNote: 7.1.1
Encoding: UTF-8
VignetteBuilder: knitr
Remotes: rstudio/bslib
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
rmarkdown 2.7
================================================================================

- `html_document` (and `html_document_base`)'s `theme` parameter now understand `bslib::bs_theme()` objects/arguments, meaning that one may opt-into Bootstrap 4 and more easily create custom themes. For examples, see <https://github.com/rstudio/rmarkdown/pull/1706>, and for context, see <https://rstudio.github.io/bslib> (thanks, @cpsievert, #1706)

- Files with `.scss`/`.sass` extension (i.e., Sass files) provided to `html_document`'s `css` parameter are now compiled to CSS using the `{sass}` package. Also, if `theme` is a `{bslib}` object, these Sass files may utilize Sass code inside the `theme` (thanks, @cpsievert, #1706)

- Fix an issue with line numbering in code chunks when `.numberlines` with Pandoc's highlighting (thanks, @aosavi, #1876)

- Accept `latex="{options}"`, `latex=1`, or `latex=true` for Latex Divs.
Expand Down
91 changes: 86 additions & 5 deletions R/html_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,19 @@ html_dependency_jqueryui <- function() {
#' @rdname html-dependencies
#' @export
html_dependency_bootstrap <- function(theme) {

if (identical(theme, "default")) {
theme <- "bootstrap"
theme <- resolve_theme(theme)
if (is_bs_theme(theme)) {
Comment thread
cpsievert marked this conversation as resolved.
Resolved
# TODO: would it make sense for these additional rules to come as a part of
# bslib::bs_theme_dependencies() (for consistency sake)?
h1_size <- if ("3" %in% theme_version(theme)) "font-size-h1" else "h1-font-size"
theme <- bslib::bs_add_rules(
theme, c(
paste0("h1.title {margin-top: 1.25rem; font-size: 1.15 * $", h1_size, "}"),
"pre:not([class]) { background-color: $body-bg }"
)
)
return(bslib::bs_theme_dependencies(theme))
}

htmlDependency(
name = "bootstrap",
version = "3.3.5",
Expand All @@ -55,9 +63,82 @@ html_dependency_bootstrap <- function(theme) {
# These shims are necessary for IE 8 compatibility
"shim/html5shiv.min.js",
"shim/respond.min.js"),
stylesheet = paste0("css/", theme, ".min.css"))
stylesheet = paste0("css/", theme, ".min.css"),
# CSS rules yanked from inst/rmd/h/default.html that should remain for historical
# reasons, but shouldn't be included if bslib is relevant
head = format(tags$style(HTML(
"h1 {font-size: 34px;}
h1.title {font-size: 38px;}
h2 {font-size: 30px;}
h3 {font-size: 24px;}
h4 {font-size: 18px;}
h5 {font-size: 16px;}
h6 {font-size: 12px;}
code {color: inherit; background-color: rgba(0, 0, 0, 0.04);}
pre:not([class]) { background-color: white }"
)))
Comment thread
cpsievert marked this conversation as resolved.
Resolved
)
}

bootstrap_dependencies <- function(theme) {
deps <- html_dependency_bootstrap(theme)
if (inherits(deps, "html_dependency")) list(deps) else deps
}

resolve_theme <- function(theme) {
# theme = NULL means no Bootstrap
if (is.null(theme)) return(theme)
# Bootstrap/Bootswatch 3 names (backwards-compatibility)
if (is.character(theme)) {
if (length(theme) != 1) {
stop("`theme` must be character vector of length 1.")
}
if (theme %in% c("bootstrap", "default")) {
return("bootstrap")
}
return(match.arg(theme, themes()))
}
if (is.list(theme)) {
if (!is_available("bslib")) {
stop("Providing a list to `theme` requires the bslib package.")
}
return(as_bs_theme(theme))
}
stop(
"`theme` expects any one of the following values: ",
"(1) NULL (no Bootstrap), ",
"(2) a character string referencing a Bootswatch 3 theme name, ",
"(3) a list of arguments to bslib::bs_theme(), ",
"(4) a bslib::bs_theme() object."
)
}

# At the moment, theme may be either NULL (no Bootstrap), a string (Bootswatch
# 3 name), a bslib::bs_theme(), or a list of arguments to bs_theme().
as_bs_theme <- function(theme) {
if (is_bs_theme(theme)) {
return(theme)
}
if (is.list(theme)) {
return(do.call(bslib::bs_theme, theme))
}
NULL
}

is_bs_theme <- function(theme) {
is_available("bslib") &&
bslib::is_bs_theme(theme)
}

theme_version <- function(theme) {
if (is_bs_theme(theme)) {
bslib::theme_version(theme)
} else {
substr(html_dependency_bootstrap("default")$version, 1, 1)
}
}


# Create an HTML dependency for tocify
#' @rdname html-dependencies
#' @export
Expand Down
69 changes: 30 additions & 39 deletions R/html_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#' the markdown syntax for citations in the
#' \href{https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html}{Bibliographies
#' and Citations} article in the online documentation.
#'@md
#'@inheritParams output_format
#'@param toc \code{TRUE} to include a table of contents in the output
#'@param toc_depth Depth of headers to include in table of contents
Expand Down Expand Up @@ -46,10 +47,15 @@
#' scripts, stylesheets, images, and videos. Note that even for self contained
#' documents MathJax is still loaded externally (this is necessary because of
#' its size).
#'@param theme Visual theme ("default", "cerulean", "journal", "flatly",
#' "darkly", "readable", "spacelab", "united", "cosmo", "lumen", "paper",
#' "sandstone", "simplex", or "yeti"). Pass \code{NULL} for no theme (in this
#' case you can use the \code{css} parameter to add your own styles).
#'@param theme One of the following:
#' * A [bslib::bs_theme()] object (or a list of [bslib::bs_theme()] argument values)
#' * Use this option for custom themes using Bootstrap 4 or 3.
#' * In this case, any `.scss`/`.sass` files provided to the `css`
#' parameter may utilize the `theme`'s underlying Sass utilities
#' (e.g., variables, mixins, etc).
#' * `NULL` for no theme (i.e., no [html_dependency_bootstrap()]).
#' * A character string specifying a [Bootswatch 3](https://bootswatch.com/3/)
#' theme name (for backwards-compatibility).
#'@param highlight Syntax highlighting style. Supported styles include
#' "default", "tango", "pygments", "kate", "monochrome", "espresso", "zenburn",
#' "haddock", and "textmate". Pass \code{NULL} to prevent syntax highlighting.
Expand Down Expand Up @@ -240,6 +246,9 @@ html_document <- function(toc = FALSE,
# table of contents
args <- c(args, pandoc_toc_args(toc, toc_depth))

# makes downstream logic easier to reason about
theme <- resolve_theme(theme)

# toc_float
if (toc && !identical(toc_float, FALSE)) {

Expand Down Expand Up @@ -321,9 +330,23 @@ html_document <- function(toc = FALSE,
if (number_sections)
args <- c(args, "--number-sections")

# additional css
for (css_file in css)
args <- c(args, "--css", pandoc_path_arg(css_file, backslash = FALSE))
# additional sass/css
for (f in css) {
if (is_bs_theme(theme)) {
theme <- bslib::bs_add_rules(theme, sass::sass_file(f))
next
}
is_sass <- grepl("\\.s[ac]ss$", f)
if (is_sass) {
f <- sass::sass(
sass::sass_file(f),
output = sub("\\.s[ac]ss$", ".css", f),
options = sass::sass_options(output_style = "compressed")
)
}
args <- c(args, "--css", pandoc_path_arg(f, backslash = FALSE))
}


# manage list of exit_actions (backing out changes to knitr options)
exit_actions <- list()
Expand Down Expand Up @@ -394,8 +417,6 @@ html_document <- function(toc = FALSE,

# flag indicating we need extra navbar css and js
args <- c(args, pandoc_variable_arg("navbar", "1"))
# variables controlling padding from navbar
args <- c(args, pandoc_body_padding_variable_args(theme))

# navbar icon dependencies
iconDeps <- navbar_icon_dependencies(navbar)
Expand Down Expand Up @@ -541,35 +562,6 @@ mathjax_config <- function() {
"MathJax.js?config=TeX-AMS-MML_HTMLorMML"
}

# variable which controls body offset (depends on height of navbar in theme)
pandoc_body_padding_variable_args <- function(theme) {

# height of navbar in bootstrap 3.3.5
navbarHeights <- c("default" = 51,
"cerulean" = 51,
"journal" = 61 ,
"flatly" = 60,
"darkly" = 60,
"readable" = 66,
"spacelab" = 52,
"united" = 51,
"cosmo" = 51,
"lumen" = 54,
"paper" = 64,
"sandstone" = 61,
"simplex" = 41,
"yeti" = 45)

# body padding is navbar height
bodyPadding <- navbarHeights[[theme]]

# header padding is bodyPadding + 5
headerPadding <- bodyPadding + 5

# return variables
c(pandoc_variable_arg("body_padding", bodyPadding),
pandoc_variable_arg("header_padding", headerPadding))
}

navbar_html_from_yaml <- function(navbar_yaml) {

Expand Down Expand Up @@ -689,4 +681,3 @@ navbar_link_text <- function(x, ...) {
tagList(x$text, ...)
}


40 changes: 28 additions & 12 deletions R/html_document_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ html_document_base <- function(theme = NULL,

output_dir <- ""

# dummy pre_knit and post_knit functions so that merging of outputs works
pre_knit <- function(input, ...) {}
theme <- resolve_theme(theme)

# In the bs_theme() case, we set the theme globally so that knitting code may
# alter it before we ultimately compile it into an HTML dependency.
old_theme <- NULL
pre_knit <- function(input, ...) {
if (is_bs_theme(theme)) {
old_theme <<- bslib::bs_global_set(theme)
}
}
post_knit <- function(metadata, input_file, runtime, ...) {}
on_exit <- function() {
# In this case, we know we've altered global state, so restore the old theme
if (is_bs_theme(theme)) bslib::bs_global_set(old_theme)
}

# pre_processor
pre_processor <- function(metadata, input_file, runtime, knit_meta,
Expand All @@ -66,26 +78,25 @@ html_document_base <- function(theme = NULL,
# copy supplied output_dir (for use in post-processor)
output_dir <<- output_dir

# handle theme
if (!is.null(theme)) {
theme <- match.arg(theme, themes())
if (identical(theme, "default"))
theme <- "bootstrap"
args <- c(args, "--variable", paste0("theme:", theme))
theme_arg <- if (is.list(theme)) "bootstrap" else theme
args <- c(args, pandoc_variable_arg("theme", theme_arg))
}

# resolve and inject extras, including dependencies specified by the format
# and dependencies specified by the user (via extra_dependencies)
format_deps <- list()
format_deps <- append(format_deps, html_dependency_header_attrs())
if (!is.null(theme)) {
format_deps <- append(format_deps, list(html_dependency_jquery(),
html_dependency_bootstrap(theme)))
format_deps <- append(format_deps, list(html_dependency_jquery()))
format_deps <- append(format_deps, bootstrap_dependencies(
# If TRUE, an as_bs_theme(theme) has been set globally (so users may customize it)
if (is_bs_theme(theme)) bslib::bs_global_get() else theme
))
}
else if (isTRUE(bootstrap_compatible) && is_shiny(runtime)) {
# If we can add bootstrap for Shiny, do it
format_deps <- append(format_deps,
list(html_dependency_bootstrap("bootstrap")))
format_deps <- append(format_deps, bootstrap_dependencies("bootstrap"))
}
format_deps <- append(format_deps, extra_dependencies)

Expand Down Expand Up @@ -162,6 +173,11 @@ html_document_base <- function(theme = NULL,
output_file
}

if (!is.null(theme)) {
bs3 <- identical("3", theme_version(theme))
args <- c(args, pandoc_variable_arg("bs3", bs3))
}

output_format(
knitr = NULL,
pandoc = pandoc_options(
Expand All @@ -172,6 +188,7 @@ html_document_base <- function(theme = NULL,
clean_supporting = FALSE,
pre_knit = pre_knit,
post_knit = post_knit,
on_exit = on_exit,
pre_processor = pre_processor,
intermediates_generator = intermediates_generator,
post_processor = post_processor
Expand All @@ -184,4 +201,3 @@ extract_preserve_chunks <- function(input_file, extract = extractPreserveChunks)
if (!identical(preserve$value, input_str)) write_utf8(preserve$value, input_file)
preserve$chunks
}

Loading