From 4eaff479860dba6ebd840c0c6c242454d0117823 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 30 Nov 2020 18:38:13 +0100 Subject: [PATCH] handle new prefix in fontawesome 5 --- R/html_dependencies.R | 6 ++++-- R/html_document.R | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/R/html_dependencies.R b/R/html_dependencies.R index c51f8c397e..23892ca7f6 100644 --- a/R/html_dependencies.R +++ b/R/html_dependencies.R @@ -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) { @@ -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 diff --git a/R/html_document.R b/R/html_document.R index 2c23dbf2b4..7c40d6b6f8 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -646,7 +646,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, ...)