blob: 5d3d6c5ae9bf36195fd9dc62348d8d12a886e043 [file] [log] [blame]
Hao Zhueaef4312018-01-10 17:05:23 -05001#' @export
Hao Zhub9da01c2018-01-14 21:01:57 -05002print.kableExtra <- function(x, ...) {
Hao Zhueaef4312018-01-10 17:05:23 -05003 html_header <- htmltools::tags$head(
4 rmarkdown::html_dependency_jquery(),
Hao Zhu8a69ad12018-01-10 18:01:41 -05005 rmarkdown::html_dependency_bootstrap(theme = "simplex"),
6 html_dependency_kePrint()
Hao Zhueaef4312018-01-10 17:05:23 -05007 )
Hao Zhueaef4312018-01-10 17:05:23 -05008 html_table <- htmltools::HTML(as.character(x))
Hao Zhu8c8ac8b2018-01-23 23:45:13 -05009 html_result <- htmltools::tagList(html_header, html_table)
Hao Zhu57761542018-03-26 16:32:56 -040010 if (interactive() & rstudioapi::isAvailable()) {
Hao Zhu5b71b2d2018-03-26 16:31:09 -040011 htmltools::html_print(html_result, viewer = rstudioapi::viewer)
12 }
Hao Zhu5e1740d2019-01-21 11:54:15 -050013 print(html_result)
Hao Zhueaef4312018-01-10 17:05:23 -050014}
15
Hao Zhu6107f372018-05-21 00:23:26 -040016#' HTML dependency for js script to enable bootstrap tooltip and popup message
17#'
Hao Zhue5b9bff2018-05-20 17:40:03 -040018#' @export
Hao Zhu8a69ad12018-01-10 18:01:41 -050019html_dependency_kePrint <- function() {
20 htmlDependency(name = "kePrint",
21 version = "0.0.1",
Hao Zhu7cb0e372018-01-10 18:29:30 -050022 src = system.file("kePrint-0.0.1",
Hao Zhu8a69ad12018-01-10 18:01:41 -050023 package = "kableExtra"),
24 script = "kePrint.js")
25}
Hao Zhueaef4312018-01-10 17:05:23 -050026
Hao Zhu6107f372018-05-21 00:23:26 -040027#' HTML dependency for Twitter bootstrap (table only)
28#'
Hao Zhueaef4312018-01-10 17:05:23 -050029#' @export
Hao Zhue5b9bff2018-05-20 17:40:03 -040030html_dependency_bsTable <- function() {
31 htmlDependency(name = "bsTable",
32 version = "3.3.7",
33 src = system.file("bootstrapTable-3.3.7",
34 package = "kableExtra"),
35 stylesheet = "bootstrapTable.min.css")
36}
37
38#' @export
Hao Zhuc8306792018-01-11 12:34:35 -050039knit_print.kableExtra <- function(x, ...) {
Hao Zhueaef4312018-01-10 17:05:23 -050040 x <- paste0(x, "\n\n")
Hao Zhuc1450882018-10-03 17:56:26 -040041 kp_dependency <- getOption("kableExtra.knit_print.dependency",
42 default = TRUE)
43 if (kp_dependency) {
44 meta_list <- list(html_dependency_kePrint())
45 bs <- getOption("kableExtra.html.bsTable", default = FALSE)
46 if (bs) {
47 meta_list[[2]] <- html_dependency_bsTable()
48 }
49 } else {
50 meta_list <- NULL
Hao Zhue5b9bff2018-05-20 17:40:03 -040051 }
52 asis_output(x, meta = meta_list)
Hao Zhueaef4312018-01-10 17:05:23 -050053}
54
55
56
57