Skip to content

Commit

Permalink
Insure fontawesome V4 compatibility in navbar (#1994)
Browse files Browse the repository at this point in the history
This allows to have old navbar definition to work with new FA5 also. It was a breaking change previously to this. 

Co-authored-by: Yihui Xie <[email protected]>
  • Loading branch information
cderv and yihui authored May 18, 2021
1 parent d8b1979 commit f798b78
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ rmarkdown 2.9

- Floating ToC in `html_document` can now hide headings with unnumbered and unlisted classes (thanks, @atusy, #1993).

- Fix prefix handling in R Markdown website's navbar for Fontawesome V5 and compatibility with V4. For icon only available in V5, the full prefix + name should be use, especially with new `fab` prefix (e.g. `fab fa-r-project`). If no prefix is used (e.g `fa-home` instead of `fas fa-home`), the `fa` prefix will be added for V4 compatibility as it has been deprecated in V5. We advice to use the full prefix + name for icons following Fontawesome documentation. (#1994)

- `rmarkdown::site_generator()` can hang session waiting for input when the `site` field is not found in the YAML frontmatter of `index.Rmd` (thanks, @kevinushey @mirh, #2043).


Expand Down
4 changes: 2 additions & 2 deletions R/html_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,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 @@ -232,7 +232,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 @@ -652,15 +652,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

0 comments on commit f798b78

Please sign in to comment.