Skip to content

Commit

Permalink
fix #1554: handle new prefix in fontawesome 5 (#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
cderv authored Dec 1, 2020
1 parent 8f047e0 commit b5e4b9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
6 changes: 4 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 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,9 @@ navbar_icon_dependencies <- function(navbar) {
libs <- unique(libs)

# return their dependencies
html_dependencies_fonts("fa fa" %in% libs, "ion ion" %in% libs)
any_fa <- any(grepl("fa\\w fa", libs))
any_ion <- any(grepl("ion ion", libs))
html_dependencies_fonts(any_fa, any_ion)
}

# utility function to return a list of font dependencies based
Expand Down
13 changes: 12 additions & 1 deletion R/html_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,18 @@ navbar_link_text <- function(x, ...) {
iconset <- split[[1]][[1]]
else
iconset <- ""
tagList(tags$span(class = paste(iconset, x$icon)), " ", x$text, ...)
# check if a full class is passed for fontawesome
# use default 'fas' otherwise
# https://github.com/rstudio/rmarkdown/issues/1554
class = if (grepl("^fa\\w fa", iconset)) {
x$icon
} else if (iconset == "fa") {
paste("fas", x$icon)
} else {
# should be other than FontAwesome
paste(iconset, x$icon)
}
tagList(tags$span(class = class), " ", x$text, ...)
}
else
tagList(x$text, ...)
Expand Down

0 comments on commit b5e4b9c

Please sign in to comment.