add text & background color option in column_spec & row_spec as #43
diff --git a/R/row_spec.R b/R/row_spec.R
index 55a8bed..6615365 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -19,7 +19,8 @@
#'
#' @export
row_spec <- function(kable_input, row,
- bold = FALSE, italic = FALSE, monospace = FALSE) {
+ bold = FALSE, italic = FALSE, monospace = FALSE,
+ color = NULL, background = NULL) {
if (!is.numeric(row)) {
stop("row must be a numeric value")
}
@@ -29,14 +30,17 @@
return(kable_input)
}
if (kable_format == "html") {
- return(row_spec_html(kable_input, row, bold, italic, monospace))
+ return(row_spec_html(kable_input, row, bold, italic, monospace,
+ color, background))
}
if (kable_format == "latex") {
- return(row_spec_latex(kable_input, row, bold, italic, monospace))
+ return(row_spec_latex(kable_input, row, bold, italic, monospace,
+ color, background))
}
}
-row_spec_html <- function(kable_input, row, bold, italic, monospace) {
+row_spec_html <- function(kable_input, row, bold, italic, monospace,
+ color, background) {
kable_attrs <- attributes(kable_input)
kable_xml <- read_kable_as_xml(kable_input)
kable_tbody <- xml_tpart(kable_xml, "tbody")
@@ -63,6 +67,15 @@
xml_attr(target_cell, "style") <- paste0(xml_attr(target_cell, "style"),
"font-family: monospace;")
}
+ if (!is.null(color)) {
+ xml_attr(target_cell, "style") <- paste0(xml_attr(target_cell, "style"),
+ "color: ", color, ";")
+ }
+ if (!is.null(background)) {
+ xml_attr(target_cell, "style") <- paste0(xml_attr(target_cell, "style"),
+ "background-color: ",
+ background, ";")
+ }
}
out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs