solve the XML declaration problem
diff --git a/R/add_header_above.R b/R/add_header_above.R
index 1242868..5384f4d 100644
--- a/R/add_header_above.R
+++ b/R/add_header_above.R
@@ -53,8 +53,7 @@
new_header_row <- htmlTable_new_header_generator(header, bold, italic)
xml_add_child(kable_xml_thead, new_header_row, .where = 0)
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
return(out)
}
diff --git a/R/add_indent.R b/R/add_indent.R
index abcf058..cb4c141 100644
--- a/R/add_indent.R
+++ b/R/add_indent.R
@@ -79,8 +79,7 @@
xml_attr(node_to_edit, "indentLevel") <- indentLevel + 1
}
}
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
return(out)
}
diff --git a/R/collapse_rows.R b/R/collapse_rows.R
index d260362..7f21996 100644
--- a/R/collapse_rows.R
+++ b/R/collapse_rows.R
@@ -64,8 +64,7 @@
}
}
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
return(out)
}
diff --git a/R/column_spec.R b/R/column_spec.R
index f936305..7af7431 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -80,8 +80,7 @@
"font-family: monospace;")
}
}
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
return(out)
}
diff --git a/R/group_rows.R b/R/group_rows.R
index c38aaae..7e2df67 100644
--- a/R/group_rows.R
+++ b/R/group_rows.R
@@ -68,8 +68,7 @@
xml_add_sibling(starting_node, group_header_row, .where = "before")
# add indentations to items
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
attr(out, "group_header_rows") <- c(attr(out, "group_header_rows"), group_seq[1])
out <- add_indent(out, positions = seq(start_row, end_row))
diff --git a/R/kable_styling.R b/R/kable_styling.R
index 385b96f..fbd26f9 100644
--- a/R/kable_styling.R
+++ b/R/kable_styling.R
@@ -156,8 +156,7 @@
xml_attr(kable_xml, "style") <- paste(kable_xml_style, collapse = " ")
}
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
return(out)
}
@@ -358,3 +357,5 @@
"\\endgroup"
))
}
+
+
diff --git a/R/row_spec.R b/R/row_spec.R
index 4944f6d..75e301b 100644
--- a/R/row_spec.R
+++ b/R/row_spec.R
@@ -58,8 +58,7 @@
"font-style: italic;")
}
}
- out <- structure(as.character(kable_xml), format = "html",
- class = "knitr_kable")
+ out <- as_kable_xml(kable_xml)
attributes(out) <- kable_attrs
return(out)
}
diff --git a/R/util.R b/R/util.R
index e576ef4..9d4146e 100644
--- a/R/util.R
+++ b/R/util.R
@@ -71,3 +71,11 @@
return(x)
}
+as_kable_xml <- function(x) {
+ tmp <- tempfile(fileext = ".xml")
+ write_xml(x, tmp, options = "no_declaration")
+ out <- readLines(tmp)
+ out <- paste(out, collapse = "\n ")
+ out <- structure(out, format = "html", class = "knitr_kable")
+ return(out)
+}