| @@ -344,7 +344,7 @@ style_xaringan <- function( | |||
| force(code_font_family) | |||
| force(code_font_url) | |||
| force(code_font_family_fallback) | |||
| # the defaults are google fonts | |||
| is_default <- function(type, suffix) { | |||
| # check if font arg value is from xaringanthemer_font_default | |||
| @@ -362,7 +362,7 @@ style_xaringan <- function( | |||
| r_set_font_is_google <- glue::glue("{var}_font_is_google <- {var_is_google}") | |||
| eval(parse(text = r_set_font_is_google)) | |||
| } | |||
| # Make sure font names are wrapped in quotes if they have spaces | |||
| f_args <- names(formals(sys.function())) | |||
| for (var in f_args[grepl("font_family$", f_args)]) { | |||
| @@ -371,7 +371,7 @@ style_xaringan <- function( | |||
| eval(parse(text = paste0(var, "<-quote_elements_w_spaces(", var, ")"))) | |||
| } | |||
| } | |||
| # Warn if base_font_size isn't absolute | |||
| css_abs_units <- c("cm", "mm", "Q", "in", "pc", "pt", "px") | |||
| if (!grepl(paste(tolower(css_abs_units), collapse = "|"), tolower(base_font_size))) { | |||
| @@ -385,7 +385,7 @@ style_xaringan <- function( | |||
| immediate. = TRUE | |||
| ) | |||
| } | |||
| # If certain colors aren't in hexadecimal it may cause problems with theme_xaringan() | |||
| # TODO: at some point I'd rather be able to process CSS colors or variables | |||
| colors_used_by_theme_xaringan <- list( | |||
| @@ -399,18 +399,18 @@ style_xaringan <- function( | |||
| ) | |||
| colors_used_by_theme_xaringan <- purrr::discard(colors_used_by_theme_xaringan, is.null) | |||
| colors_are_hex <- purrr::map_lgl(colors_used_by_theme_xaringan, check_color_is_hex, throw = NULL) | |||
| if (any(!colors_are_hex)) { | |||
| colors_better_as_hex <- names(colors_used_by_theme_xaringan)[!colors_are_hex] | |||
| colors_better_as_hex <- paste(colors_better_as_hex, collapse = ", ") | |||
| warning( | |||
| glue::glue("Colors that will be used by `theme_xaringan()` need to be in ", | |||
| "hexadecimal format: {colors_better_as_hex}"), | |||
| "hexadecimal format: {colors_better_as_hex}"), | |||
| immediate. = TRUE, | |||
| call. = FALSE | |||
| ) | |||
| } | |||
| # Use font_..._google args to overwrite font args | |||
| for (var in f_args[grepl("font_google$", f_args)]) { | |||
| gf <- eval(parse(text = var)) | |||
| @@ -433,10 +433,10 @@ style_xaringan <- function( | |||
| } | |||
| eval(parse(text = paste0(group, "_font_is_google <- 1"))) | |||
| } | |||
| extra_font_imports <- if (is.null(extra_fonts)) "" else list2fonts(extra_fonts) | |||
| extra_font_imports <- paste(extra_font_imports, collapse = "\n") | |||
| # convert NA arguments to NULL | |||
| for (var in f_args) { | |||
| val <- eval(parse(text = var)) | |||
| @@ -445,7 +445,7 @@ style_xaringan <- function( | |||
| is_na <- length(val) == 0 | |||
| if (is_na) assign(var, NULL, envir = sys.frame(sys.nframe())) | |||
| } | |||
| # prepare variables for template | |||
| body_font_family <- paste(c(text_font_family, text_font_family_fallback, text_font_base), collapse = ", ") | |||
| background_size_fallback <- if (is.null(background_position)) "cover" else "100%" | |||
| @@ -454,7 +454,7 @@ style_xaringan <- function( | |||
| title_slide_background_image %??% "cover" | |||
| ) | |||
| table_row_even_background_color <- table_row_even_background_color %||% background_color | |||
| # stash theme settings in package env | |||
| lapply(f_args, function(n) assign(n, get(n), envir = xaringanthemer_env)) | |||
| for (font_is_google in paste0(c("text", "code", "header"), "_font_is_google")) { | |||
| @@ -464,9 +464,9 @@ style_xaringan <- function( | |||
| envir = xaringanthemer_env | |||
| ) | |||
| } | |||
| xaringanthemer_version <- utils::packageVersion("xaringanthemer") | |||
| # prepare header background object | |||
| needs_leading_dot <- !grepl("^\\.", header_background_ignore_classes) | |||
| header_background_ignore_classes[needs_leading_dot] <- paste0( | |||
| @@ -491,9 +491,9 @@ style_xaringan <- function( | |||
| content_padding_top = header_background_content_padding_top, | |||
| ignore = header_background_ignore_classes | |||
| ) | |||
| colors <- prepare_colors(colors) | |||
| tf <- system.file("resources", "template.css", package = "xaringanthemer") | |||
| template <- readLines(tf, warn = FALSE) | |||
| template <- paste(template, collapse = "\n") | |||