added include_thead support to column_spec (part of #551)
diff --git a/R/column_spec.R b/R/column_spec.R
index bd170bf..c947573 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -138,23 +138,23 @@
border_right <- T
}
- nrows <- length(all_contents_rows)
- off <- 0
-
- bold <- ensure_len_html(bold, nrows, "bold")
- italic <- ensure_len_html(italic, nrows, "italic")
- monospace <- ensure_len_html(monospace, nrows, "monospace")
- underline <- ensure_len_html(underline, nrows, "underline")
- strikeout <- ensure_len_html(strikeout, nrows, "strikeout")
- color <- ensure_len_html(color, nrows, "color")
- background <- ensure_len_html(background, nrows,"background")
- link <- ensure_len_html(link, nrows, "link")
- new_tab <- ensure_len_html(new_tab, nrows, "new_tab")
- tooltip <- ensure_len_html(tooltip, nrows, "tooltip")
- popover <- ensure_len_html(popover, nrows, "popover")
- image <- ensure_len_html(image, nrows, "image")
-
if (include_thead) {
+ nrows <- length(all_contents_rows) + 1
+ off <- 1
+
+ bold <- ensure_len_html(bold, nrows, "bold")
+ italic <- ensure_len_html(italic, nrows, "italic")
+ monospace <- ensure_len_html(monospace, nrows, "monospace")
+ underline <- ensure_len_html(underline, nrows, "underline")
+ strikeout <- ensure_len_html(strikeout, nrows, "strikeout")
+ color <- ensure_len_html(color, nrows, "color")
+ background <- ensure_len_html(background, nrows,"background")
+ link <- ensure_len_html(link, nrows, "link")
+ new_tab <- ensure_len_html(new_tab, nrows, "new_tab")
+ tooltip <- ensure_len_html(tooltip, nrows, "tooltip")
+ popover <- ensure_len_html(popover, nrows, "popover")
+ image <- ensure_len_html(image, nrows, "image")
+
kable_thead <- xml_tpart(kable_xml, "thead")
nrow_thead <- length(xml_children(kable_thead))
for (j in column) {
@@ -164,21 +164,39 @@
bold[1], italic[1], monospace[1], underline[1], strikeout[1],
color[1], background[1], border_left, border_right,
border_l_css, border_r_css,
- extra_css[1], link[1], new_tab[1], tooltip[1], popover[1], image[1]
+ extra_css,
+ link[1], new_tab[1], tooltip[1], popover[1], image[1]
)
}
+ } else {
+ nrows <- length(all_contents_rows)
+ off <- 0
+
+ bold <- ensure_len_html(bold, nrows, "bold")
+ italic <- ensure_len_html(italic, nrows, "italic")
+ monospace <- ensure_len_html(monospace, nrows, "monospace")
+ underline <- ensure_len_html(underline, nrows, "underline")
+ strikeout <- ensure_len_html(strikeout, nrows, "strikeout")
+ color <- ensure_len_html(color, nrows, "color")
+ background <- ensure_len_html(background, nrows,"background")
+ link <- ensure_len_html(link, nrows, "link")
+ new_tab <- ensure_len_html(new_tab, nrows, "new_tab")
+ tooltip <- ensure_len_html(tooltip, nrows, "tooltip")
+ popover <- ensure_len_html(popover, nrows, "popover")
+ image <- ensure_len_html(image, nrows, "image")
}
for (i in seq(length(all_contents_rows))) {
for (j in column) {
- target_cell <- xml_child(xml_child(kable_tbody, all_contents_rows[i]), j)
+ io <- i + off
+ target_cell <- xml_child(xml_child(kable_tbody, all_contents_rows[io]), j)
column_spec_html_cell(
target_cell, width, width_min, width_max,
- bold[i], italic[i], monospace[i], underline[i], strikeout[i],
- color[i], background[i], border_left, border_right,
+ bold[io], italic[io], monospace[io], underline[io], strikeout[io],
+ color[io], background[io], border_left, border_right,
border_l_css, border_r_css,
extra_css,
- link[i], new_tab[i], tooltip[i], popover[i], image[i]
+ link[io], new_tab[io], tooltip[io], popover[io], image[io]
)
}
}