Skip to content

Commit

Permalink
CSS colors don't support numbers like in "darkgoldenrod2", so convert…
Browse files Browse the repository at this point in the history
… those to rgba() form. Fixes #726.
  • Loading branch information
dmurdoch committed Dec 3, 2023
1 parent 247c366 commit c8f6b4a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions R/spec_tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ spec_color <- function(x, alpha = 1, begin = 0, end = 1,
}

html_color_ <- function(color) {
if (substr(color, 1, 1) != "#" | nchar(color) != 9) return(color)
# HTML colors are a subset of R colors, not including
# numbered versions like darkgoldenrod2 (issue #726)
if (substr(color, 1, 1) != "#" &&
!grepl("[[:digit:]]", color) )
return(color)

rgba_code <- col2rgb(color, alpha = TRUE)
rgba_code[4] <- round(rgba_code[4] / 255, 2)
rgba_code[4] <- round(rgba_code[4])
return(paste0("rgba(", paste(rgba_code, collapse = ", "), ")"))
}

Expand Down
1 change: 0 additions & 1 deletion R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,3 @@ md_table_parser <- function(md_table) {
caption=table_caption, booktabs = TRUE,
longtable = TRUE))
}

2 changes: 2 additions & 0 deletions inst/NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ kableExtra 1.4.0
* updated kbl() parameters to match knitr::kable()
parameters in knitr 1.45. knitr versions back to 1.33
should be supported.
* cell_spec() colors like "darkgoldenrod2" weren't
shown (issue #726).



Expand Down

0 comments on commit c8f6b4a

Please sign in to comment.