Add extra_css to spec family
diff --git a/R/cell_spec.R b/R/cell_spec.R
index 0774fcb..bc7af1e 100644
--- a/R/cell_spec.R
+++ b/R/cell_spec.R
@@ -32,6 +32,7 @@
#' bootstrap module manually. Read the package vignette to see how.
#' @param link A vector of strings for url links. Can be used together with
#' tooltip and popover.
+#' @param extra_css Extra css text to be passed into the cell
#' @param escape T/F value showing whether special characters should be escaped.
#' @param background_as_tile T/F value indicating if you want to have round
#' cornered tile as background in HTML.
@@ -46,6 +47,7 @@
color = NULL, background = NULL,
align = NULL, font_size = NULL, angle = NULL,
tooltip = NULL, popover = NULL, link = NULL,
+ extra_css = NULL,
escape = TRUE,
background_as_tile = TRUE,
latex_background_in_cell = TRUE) {
@@ -61,7 +63,7 @@
if (tolower(format) == "html") {
return(cell_spec_html(x, bold, italic, monospace,
color, background, align, font_size, angle,
- tooltip, popover, link,
+ tooltip, popover, link, extra_css,
escape, background_as_tile))
}
if (tolower(format) == "latex") {
@@ -73,7 +75,7 @@
cell_spec_html <- function(x, bold, italic, monospace,
color, background, align, font_size, angle,
- tooltip, popover, link,
+ tooltip, popover, link, extra_css,
escape, background_as_tile) {
if (escape) x <- escape_html(x)
cell_style <- NULL
@@ -92,6 +94,9 @@
"background-color: ", html_color(background), ";"
)
}
+ if (!is.null(extra_css)) {
+ cell_style <- paste0(cell_style, extra_css)
+ }
if (!is.null(align)) {
cell_style <- paste0(cell_style, "text-align: ", align, ";")
}
diff --git a/R/column_spec.R b/R/column_spec.R
index 55e01a1..a640a4d 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -23,6 +23,8 @@
#' @param border_right A logical variable indicating whether there should be a
#' border line on the right of the selected column. In HTML, you can also pass
#' in a character string for the CSS of the border line
+#' @param extra_css Extra css text to be passed into the cells of the row. Note
+#' that it's not for the whole column but to each individual cells
#'
#' @examples x <- knitr::kable(head(mtcars), "html")
#' column_spec(x, 1:2, width = "20em", bold = TRUE, italic = TRUE)
@@ -31,7 +33,8 @@
column_spec <- function(kable_input, column,
width = NULL, bold = FALSE, italic = FALSE,
monospace = FALSE, color = NULL, background = NULL,
- border_left = FALSE, border_right = FALSE) {
+ border_left = FALSE, border_right = FALSE,
+ extra_css = NULL) {
if (!is.numeric(column)) {
stop("column must be numeric. ")
}
@@ -44,7 +47,7 @@
return(column_spec_html(kable_input, column, width,
bold, italic, monospace,
color, background,
- border_left, border_right))
+ border_left, border_right, extra_css))
}
if (kable_format == "latex") {
return(column_spec_latex(kable_input, column, width,
@@ -57,7 +60,7 @@
column_spec_html <- function(kable_input, column, width,
bold, italic, monospace,
color, background,
- border_left, border_right) {
+ border_left, border_right, extra_css) {
kable_attrs <- attributes(kable_input)
kable_xml <- read_kable_as_xml(kable_input)
kable_tbody <- xml_tpart(kable_xml, "tbody")
@@ -118,6 +121,10 @@
xml_attr(target_cell, "style") <- paste0(xml_attr(target_cell, "style"),
"border-right:", border_r_css, ";")
}
+ if (!is.null(extra_css)) {
+ xml_attr(target_cell, "style") <- paste0(xml_attr(target_cell, "style"),
+ extra_css)
+ }
}
}
diff --git a/R/row_spec.R b/R/row_spec.R
index 6ab31ec..d58493c 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -23,6 +23,8 @@
#' options including `xx-small`, `x-small`, `small`, `medium`, `large`,
#' `x-large`, `xx-large`, `smaller`, `larger`, `initial` and `inherit`.
#' @param angle 0-360, degree that the text will rotate.
+#' @param extra_css Extra css text to be passed into the cells of the row. Note
+#' that it's not for the whole row.
#'
#' @examples x <- knitr::kable(head(mtcars), "html")
#' row_spec(x, 1:2, bold = TRUE, italic = TRUE)
@@ -31,7 +33,7 @@
row_spec <- function(kable_input, row,
bold = FALSE, italic = FALSE, monospace = FALSE,
color = NULL, background = NULL, align = NULL,
- font_size = NULL, angle = NULL) {
+ font_size = NULL, angle = NULL, extra_css) {
if (!is.numeric(row)) {
stop("row must be numeric. ")
}
@@ -42,7 +44,8 @@
}
if (kable_format == "html") {
return(row_spec_html(kable_input, row, bold, italic, monospace,
- color, background, align, font_size, angle))
+ color, background, align, font_size, angle,
+ extra_css))
}
if (kable_format == "latex") {
return(row_spec_latex(kable_input, row, bold, italic, monospace,
@@ -51,7 +54,8 @@
}
row_spec_html <- function(kable_input, row, bold, italic, monospace,
- color, background, align, font_size, angle) {
+ color, background, align, font_size, angle,
+ extra_css) {
kable_attrs <- attributes(kable_input)
kable_xml <- read_kable_as_xml(kable_input)
@@ -67,7 +71,7 @@
for (theader_i in 1:length(xml_children(original_header_row))) {
target_header_cell <- xml_child(original_header_row, theader_i)
xml_cell_style(target_header_cell, bold, italic, monospace, color, background,
- align, font_size, angle)
+ align, font_size, angle, extra_css)
}
row <- row[row != 0]
}
@@ -86,7 +90,7 @@
for (i in 1:length(xml_children(target_row))) {
target_cell <- xml_child(target_row, i)
xml_cell_style(target_cell, bold, italic, monospace, color, background,
- align, font_size, angle)
+ align, font_size, angle, extra_css)
}
}
}
@@ -97,7 +101,7 @@
}
xml_cell_style <- function(x, bold, italic, monospace, color, background,
- align, font_size, angle) {
+ align, font_size, angle, extra_css) {
if (bold) {
xml_attr(x, "style") <- paste0(xml_attr(x, "style"),
"font-weight: bold;")
@@ -136,6 +140,9 @@
"deg); transform: rotate(", angle,
"deg);")
}
+ if (!is.null(extra_css)) {
+ xml_attr(x, "style") <- paste0(xml_attr(x, "style"), extra_css)
+ }
return(x)
}