diff --git a/R/bs-theme-preset-brand.R b/R/bs-theme-preset-brand.R index 05888a549..94a54f0ce 100644 --- a/R/bs-theme-preset-brand.R +++ b/R/bs-theme-preset-brand.R @@ -625,6 +625,7 @@ as_brand_yml <- function(brand = list()) { # Normalize brand internals !! MINIMAL VALIDATION !! brand <- brand_meta_normalize(brand) brand <- brand_color_normalize(brand) + brand <- brand_typography_normalize(brand) class(brand) <- "brand_yml" brand @@ -674,6 +675,30 @@ brand_color_normalize <- function(brand) { brand } +brand_typography_normalize <- function(brand) { + if (!brand_has(brand, "typography")) { + return(brand) + } + + expand_family <- c( + "base", + "headings", + "monospace", + "monospace-inline", + "monospace-block" + ) + + for (field in expand_family) { + if (brand_has_string(brand, "typography", field)) { + brand[["typography"]][[field]] <- list( + family = brand[["typography"]][[field]] + ) + } + } + + brand +} + brand_color_pluck <- function(brand, key) { if (!brand_has(brand, "color")) { return(key) diff --git a/tests/testthat/test-bs-theme-preset-brand.R b/tests/testthat/test-bs-theme-preset-brand.R index fdedf9052..3d2c61a1c 100644 --- a/tests/testthat/test-bs-theme-preset-brand.R +++ b/tests/testthat/test-bs-theme-preset-brand.R @@ -15,6 +15,24 @@ describe("as_brand_yml()", { expect_equal(brand$color$palette$red, brand$color$primary) expect_equal(brand$color$secondary, "berry") }) + + it("normalizes font family choices", { + brand <- list( + typography = list( + base = "Times New Roman", + headings = "Helvetica", + monospace = "Courier New", + "monospace-inline" = "Fira Code" + ) + ) + + brand <- as_brand_yml(brand) + expect_s3_class(brand, "brand_yml") + expect_equal(brand$typography$base$family, "Times New Roman") + expect_equal(brand$typography$headings$family, "Helvetica") + expect_equal(brand$typography[["monospace"]]$family, "Courier New") + expect_equal(brand$typography[["monospace-inline"]]$family, "Fira Code") + }) }) describe("brand_resolve()", {