diff --git a/R/kable_styling.R b/R/kable_styling.R index 97073e5..b1666f5 100644 --- a/R/kable_styling.R +++ b/R/kable_styling.R @@ -257,8 +257,9 @@ htmlTable_styling <- function(kable_input, kable_xml_style <- xml_attr(kable_xml, "style") } if (!is.null(font_size)) { + if (is.numeric(font_size)) font_size <- paste0(font_size, "px") kable_xml_style <- c(kable_xml_style, - paste0("font-size: ", font_size, "px;")) + paste0("font-size: ", font_size, ";")) kable_caption_node <- xml_tpart(kable_xml, "caption") if (!is.null(kable_caption_node)) { xml_attr(kable_caption_node, "style") <- "font-size: initial !important;" diff --git a/R/row_spec.R b/R/row_spec.R index be2fa98..cc1bd5e 100644 --- a/R/row_spec.R +++ b/R/row_spec.R @@ -166,8 +166,9 @@ xml_cell_style <- function(x, bold, italic, monospace, "text-align: ", align, ";") } if (!is.null(font_size)) { + if (is.numeric(font_size)) font_size <- paste0(font_size, "px") xml_attr(x, "style") <- paste0(xml_attr(x, "style"), - "font-size: ", font_size, "px;") + "font-size: ", font_size, ";") } if (!is.null(angle)) { xml_attr(x, "style") <- paste0(xml_attr(x, "style"), diff --git a/tests/testthat/_snaps/row_spec.md b/tests/testthat/_snaps/row_spec.md index 6e1b594..73bd6a0 100644 --- a/tests/testthat/_snaps/row_spec.md +++ b/tests/testthat/_snaps/row_spec.md @@ -189,3 +189,37 @@ \bottomrule \end{tabular} +# Issue #576: string font_size in html + + Code + cat(data.frame(a = c("foo", "bar", "foo", "bar", "foo", "bar")) %>% kbl() %>% + row_spec(3, font_size = "xx-large")) + Output + + + + + + + + + + + + + + + + + + + + + + + + + + +
a
foo
bar
foo
bar
foo
bar
+ diff --git a/tests/testthat/test-row_spec.R b/tests/testthat/test-row_spec.R index fe4a8ac..025400f 100644 --- a/tests/testthat/test-row_spec.R +++ b/tests/testthat/test-row_spec.R @@ -77,4 +77,15 @@ test_that("awesome table example", { row_spec(c(1:7, 11:12) - 1, extra_latex_after = "\\rowcolor{gray!6}") %>% collapse_rows(1, latex_hline = "none") ) +}) + + + +test_that("Issue #576: string font_size in html", { + expect_snapshot( + data.frame(a = c("foo", "bar", "foo", "bar", "foo", "bar")) %>% + kbl() %>% + row_spec(3, font_size = "xx-large") |> + cat() + ) }) \ No newline at end of file