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

Insure fontawesome V4 compatibility in navbar #1994

Merged
merged 7 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions R/html_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ navbar_icon_dependencies <- function(navbar) {
source <- read_utf8(navbar)

# find icon references
res <- regexec('<(span|i) +class *= *("|\') *(fa\\w fa|ion ion)-', source)
res <- regexec('<(span|i) +class *= *("|\') *(fa\\w? fa|ion ion)-', source)
matches <- regmatches(source, res)
libs <- c()
for (match in matches) {
Expand All @@ -151,7 +151,7 @@ navbar_icon_dependencies <- function(navbar) {
libs <- unique(libs)

# return their dependencies
any_fa <- any(grepl("fa\\w fa", libs))
any_fa <- any(grepl("fa\\w? fa", libs))
any_ion <- any(grepl("ion ion", libs))
html_dependencies_fonts(any_fa, any_ion)
}
Expand Down
13 changes: 8 additions & 5 deletions R/html_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -672,15 +672,18 @@ navbar_link_text <- function(x, ...) {
iconset <- split[[1]][[1]]
else
iconset <- ""
# check if a full class is passed for fontawesome
# use default 'fas' otherwise
# check if a full class is passed for fontawesome = V5
# Add fa deprecated fa prefix otherwise = V4 compatibility
# https://github.com/rstudio/rmarkdown/issues/1554
class = if (grepl("^fa\\w fa", iconset)) {
class = if (grepl("^fa\\w? fa", iconset)) {
# Fontawesome 5 - full new prefix + name must be passed
# if old fa prefix is passed - keep it for compatibility
x$icon
} else if (iconset == "fa") {
paste("fas", x$icon)
# Fontawesome 4 compatibility - Add deprecated fa prefix
paste("fa", x$icon)
} else {
# should be other than FontAwesome
# Other Icon sets
paste(iconset, x$icon)
}
tagList(tags$span(class = class), " ", x$text, ...)
Expand Down