Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Bootstrap 4 #1688

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f105ab9
drop support for IE8
yihui Oct 29, 2019
d0a3a0e
delete unused files
yihui Oct 29, 2019
80d497e
close #1260: upgrade Bootstrap from v3 to v4
yihui Oct 30, 2019
3d98410
an R script to download Bootstrap CSS and JS files
yihui Oct 30, 2019
03c04e6
tweak styles for <pre> and <code>, which were previously defined in B…
yihui Oct 30, 2019
c60d8f1
not sure where these .row-fluid and .fluid-row classes came from, but…
yihui Oct 31, 2019
a298162
up grid sizes by one level
yihui Oct 31, 2019
8fea599
.pull-right -> .float-right; .btn-default -> .btn-secondary; remove s…
yihui Oct 31, 2019
eead1ea
use <a> directly in the dropdown menu, instead of <li><a>; add the .d…
yihui Oct 31, 2019
7ffb64c
the separator's class should be .dropdown-divider instead of .divider…
yihui Oct 31, 2019
8a7df59
class name 'in' -> 'show'
yihui Oct 31, 2019
65178ca
.btn-default -> .btn-secondary; .btn-xs -> .btn-sm; .pull-right -> .f…
yihui Oct 31, 2019
2856fee
for tabset titles, <a> should have the class 'nav-link', and <li> sho…
yihui Oct 31, 2019
0632f2d
the 'active' class should be added to <a> instead of <li>
yihui Oct 31, 2019
351c855
rename themes paper to materia and readable to litera
yihui Oct 31, 2019
bab60bc
download all themes from bootswatch.com, and replace the CSS @import …
yihui Nov 1, 2019
e14a343
download themes from the bootswatch API instead of parsing its homepa…
yihui Nov 1, 2019
275c5b2
dynamically list the available themes instead of hardcoding them in t…
yihui Nov 1, 2019
0737508
navbar-default has been renamed to navbar-light; navbar-inverse is na…
yihui Nov 5, 2019
77b933b
cosmetic
yihui Nov 5, 2019
a513aa3
the menu divider should be <div class="dropdown-divider"> instead of …
yihui Nov 5, 2019
23eb382
use <h6> instead of <li> for dropdown headers (not strictly necessary…
yihui Nov 5, 2019
eed341e
update the link to the doc of navbar
yihui Nov 5, 2019
2eda617
make the navbar type a vector of length 2: the first element specifie…
yihui Nov 5, 2019
57e3ae8
generate navbar menus for Bootstrap 4
yihui Nov 5, 2019
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
rmarkdown 1.17
================================================================================

- Upgraded Bootstrap v3.3.5 to v4.3.1 for HTML output formats (#1260). The support for IE 8 has been dropped. Added these new Bootstrap themes from Bootswatch.com: `cyborg`, `litera`, `lux`, `materia`, `minty`, `pulse`, `sketchy`, `slate`, `solar`, and `superhero`.

- `html_vignette()` passes `self_contained` argument value to base format (thanks, @cderv, #1668).

- `find_external_resources()` works for the `html_vignette` type again, this fixes rendering vignettes with external resources in pkgdown (regression introduced in rmarkdown 1.16, #1668).
Expand Down
18 changes: 9 additions & 9 deletions R/html_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ html_dependency_jqueryui <- function() {
#' @export
html_dependency_bootstrap <- function(theme) {

if (identical(theme, "default")) {
theme <- "bootstrap"
}
# Bootswatch renamed a few themes when upgrading to Bootstrap 4
theme <- switch(
theme, default = "bootstrap", paper = "materia", readable = "litera", theme
)

htmlDependency(
name = "bootstrap",
version = "3.3.5",
version = "4.3.1",
src = rmarkdown_system_file(file = "rmd/h/bootstrap"),
meta = list(viewport = "width=device-width, initial-scale=1"),
script = c(
"js/bootstrap.min.js",
# These shims are necessary for IE 8 compatibility
"shim/html5shiv.min.js",
"shim/respond.min.js"),
stylesheet = paste0("css/", theme, ".min.css"))
"js/bootstrap.min.js"
),
stylesheet = c(paste0("css/", theme, ".min.css"), "css/bootstrap.extra.css")
)
}

# Create an HTML dependency for tocify
Expand Down
125 changes: 44 additions & 81 deletions R/html_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
#' of a bootstrap navigation bar. For a simple example of including a navigation bar see
#' \url{https://github.com/rstudio/rmarkdown-website/blob/master/_navbar.html}.
#' For additional documentation on creating Bootstrap navigation bars see
#' \url{http://getbootstrap.com/components/#navbar}.
#' \url{https://getbootstrap.com/docs/4.3/components/navbar/}.
#'
#'
#'@section Floating Table of Contents:
Expand Down Expand Up @@ -480,20 +480,9 @@ knitr_options_html <- function(fig_width,
}

themes <- function() {
c("default",
"cerulean",
"journal",
"flatly",
"darkly",
"readable",
"spacelab",
"united",
"cosmo",
"lumen",
"paper",
"sandstone",
"simplex",
"yeti")
r <- '[.]min[.]css$'
x <- list.files(rmarkdown_system_file('rmd/h/bootstrap/css'), r)
gsub(r, '', x)
}

html_highlighters <- function() {
Expand Down Expand Up @@ -559,15 +548,19 @@ navbar_html <- function(navbar) {

# title and type
if (is.null(navbar$title)) navbar$title <- ""
if (is.null(navbar$type)) navbar$type <- "default"
if (length(navbar$type) == 0) navbar$type <- "light"
navbar$type[1] <- switch(
navbar$type[1], default = "light", inverse = "dark", navbar$type[1]
)
navbar$type <- rep(navbar$type, length.out = 2)

# menu entries
left <- navbar_links_html(navbar$left)
right <- navbar_links_html(navbar$right)

# build the navigation bar and return it as a temp file
template <- file_string(rmarkdown_system_file("rmd/h/_navbar.html"))
navbar_html <- sprintf(template, navbar$type, navbar$title, left, right)
navbar_html <- sprintf(template, navbar$type[1], navbar$type[2], navbar$title, left, right)
as_tmpfile(navbar_html)
}

Expand All @@ -579,71 +572,41 @@ navbar_links_html <- function(links) {
}

navbar_links_tags <- function(links, depth = 0L) {

if (!is.null(links)) {

tags <- lapply(links, function(x) {

if (!is.null(x$menu)) {

# sub-menu
is_submenu <- depth > 0L

if (is_submenu) {
menu_class <- "dropdown-submenu"
link_text <- navbar_link_text(x)
} else {
menu_class <- "dropdown"
link_text <- navbar_link_text(x, " ", tags$span(class = "caret"))
}

submenuLinks <- navbar_links_tags(x$menu, depth = depth + 1L)

tags$li(class = menu_class,
tags$a(
href = "#", class = "dropdown-toggle",
`data-toggle` = "dropdown", role = "button",
`aria-expanded` = "false", link_text),
tags$ul(class = "dropdown-menu", role = "menu", submenuLinks)
)

} else if (!is.null(x$text) && grepl("^\\s*-{3,}\\s*$", x$text)) {

# divider
tags$li(class = "divider")

} else if (!is.null(x$text) && is.null(x$href)) {

# header
tags$li(class = "dropdown-header", x$text)

} else {

# standard menu item
textTags <- navbar_link_text(x)
tags$li(tags$a(href = x$href, textTags))
}
})
tagList(tags)
} else {
tagList()
}
if (is.null(links)) return(tagList())
tags <- lapply(links, function(x) {
# sub-menu
link_class <- if (is_submenu <- depth > 0) "dropdown-item" else "nav-link"
if (!is.null(x$menu)) {
link_text <- navbar_link_text(x)
menu_class <- if (is_submenu) "dropdown-submenu" else "dropdown"
submenuLinks <- navbar_links_tags(x$menu, depth = depth + 1L)
tags$li(class = paste("nav-item", menu_class),
tags$a(
href = "#", class = paste(link_class, "dropdown-toggle"),
`data-toggle` = "dropdown", role = "button",
`aria-expanded` = "false", link_text),
tags$ul(class = "dropdown-menu", role = "menu", submenuLinks)
)
} else if (!is.null(x$text) && grepl("^\\s*-{3,}\\s*$", x$text)) {
# divider
tags$div(class = "dropdown-divider")
} else if (!is.null(x$text) && is.null(x$href)) {
# header
tags$h6(class = "dropdown-header", x$text)
} else {
# standard menu item
textTags <- navbar_link_text(x)
link <- tags$a(class = link_class, href = x$href, textTags)
if (is_submenu) link else tags$li(class = "nav-item", link)
}
})
tagList(tags)
}

navbar_link_text <- function(x, ...) {

if (!is.null(x$icon)) {
# find the iconset
split <- strsplit(x$icon, "-")
if (length(split[[1]]) > 1)
iconset <- split[[1]][[1]]
else
iconset <- ""
tagList(tags$span(class = paste(iconset, x$icon)), " ", x$text, ...)
}
else
tagList(x$text, ...)
if (is.null(x$icon)) return(tagList(x$text, ...))
# find the iconset
split <- strsplit(x$icon, "-")[[1]]
iconset <- if (length(split) > 1) split[[1]] else ""
tagList(tags$span(class = paste(iconset, x$icon)), " ", x$text, ...)
}



3 changes: 1 addition & 2 deletions R/html_document_base.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ html_document_base <- function(smart = TRUE,

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

Expand Down
34 changes: 14 additions & 20 deletions inst/rmd/h/_navbar.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
<nav class="navbar fixed-top navbar-expand-lg navbar-%s bg-%s">
<a class="navbar-brand" href="index.html">%s</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="navbar navbar-%s navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">%s</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
%s
</ul>
<ul class="nav navbar-nav navbar-right">
%s
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container -->
</div><!--/.navbar -->
<div class="collapse navbar-collapse" id="navbar">
<ul class="navbar-nav mr-auto">
%s
</ul>
<ul class="navbar-nav ml-auto">
%s
</ul>
</div>
</nav>
Loading