😎 Give your xaringan slides some style
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

38 lines
1.2KB

  1. # Make sure font names are wrapped in quotes if they have spaces
  2. f_args <- names(formals(sys.function()))
  3. for (var in f_args[grepl("font_family$", f_args)]) {
  4. eval(parse(text = paste0(
  5. var, "<-quote_elements_w_spaces(", var, ")"
  6. )))
  7. }
  8. # Use font_..._google args to overwrite font args
  9. for (var in f_args[grepl("font_google$", f_args)]) {
  10. gf <- eval(parse(text = var))
  11. if (is.null(gf)) next
  12. if (!inherits(gf, "google_font")) stop(
  13. "`", var, "` must be set using `google_font()`."
  14. )
  15. group <- stringr::str_split(var, "_")[[1]][1]
  16. if (group == "text") {
  17. text_font_family <- gf$family
  18. text_font_weight <- gf$weights %||% "normal"
  19. text_font_weight <- substr(text_font_weight, 1, regexpr(",", text_font_weight)[1]-1)
  20. text_font_url <- gf$url
  21. } else {
  22. for (thing in c("family", "url")) {
  23. eval(parse(text = paste0(
  24. group, "_font_", thing, " <- gf$", thing
  25. )))
  26. }
  27. }
  28. }
  29. tf <- system.file("resources", "template.css", package = "xaringanthemer")
  30. template <- readLines(tf, warn = FALSE)
  31. template <- paste(template, collapse = "\n")
  32. x <- glue::glue(template, .open = "{{", .close = "}}")
  33. cat(x, file = outfile)
  34. if (!is.null(extra_css)) write_extra_css(extra_css, outfile)
  35. outfile