blob: 95a37c00a158e5c79ee4fc087d98a53d42e27dfc [file] [log] [blame]
Hao Zhueaef4312018-01-10 17:05:23 -05001#' @export
Hao Zhub9da01c2018-01-14 21:01:57 -05002print.kableExtra <- function(x, ...) {
Hao Zhud12f4832020-08-09 15:52:37 -04003 view_html <- getOption("kableExtra_view_html", TRUE)
Hao Zhufd446082020-10-03 09:01:43 -04004 if (view_html & interactive() & rstudioapi::isAvailable()) {
Hao Zhud12f4832020-08-09 15:52:37 -04005 dep <- list(
6 rmarkdown::html_dependency_jquery(),
7 rmarkdown::html_dependency_bootstrap(theme = "cosmo"),
Hao Zhuad4ea392020-08-10 01:24:50 -04008 html_dependency_kePrint(),
9 html_dependency_lightable()
Hao Zhud12f4832020-08-09 15:52:37 -040010 )
11 html_kable <- htmltools::browsable(
12 htmltools::HTML(
13 as.character(x),
Hao Zhu012fc072020-08-20 22:31:00 -040014 '<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [["$","$"]]}})</script><script async src="https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>'
Hao Zhu47b13432020-08-03 16:20:51 -040015 )
Hao Zhud12f4832020-08-09 15:52:37 -040016 )
17 htmlDependencies(html_kable) <- dep
18 class(html_kable) <- "shiny.tag.list"
19 print(html_kable)
20 } else {
Hao Zhuad4ea392020-08-10 01:24:50 -040021 cat(as.character(x))
Hao Zhud12f4832020-08-09 15:52:37 -040022 }
Hao Zhueaef4312018-01-10 17:05:23 -050023}
24
Hao Zhu6107f372018-05-21 00:23:26 -040025#' HTML dependency for js script to enable bootstrap tooltip and popup message
26#'
Hao Zhue5b9bff2018-05-20 17:40:03 -040027#' @export
Hao Zhu8a69ad12018-01-10 18:01:41 -050028html_dependency_kePrint <- function() {
29 htmlDependency(name = "kePrint",
30 version = "0.0.1",
Hao Zhu7cb0e372018-01-10 18:29:30 -050031 src = system.file("kePrint-0.0.1",
Hao Zhu8a69ad12018-01-10 18:01:41 -050032 package = "kableExtra"),
33 script = "kePrint.js")
34}
Hao Zhueaef4312018-01-10 17:05:23 -050035
Hao Zhu6107f372018-05-21 00:23:26 -040036#' HTML dependency for Twitter bootstrap (table only)
37#'
Hao Zhueaef4312018-01-10 17:05:23 -050038#' @export
Hao Zhue5b9bff2018-05-20 17:40:03 -040039html_dependency_bsTable <- function() {
40 htmlDependency(name = "bsTable",
41 version = "3.3.7",
42 src = system.file("bootstrapTable-3.3.7",
43 package = "kableExtra"),
Hao Zhu4a888b32020-08-11 15:48:23 -040044 stylesheet = "bootstrapTable.min.css",
45 script = "bootstrapTable.js")
Hao Zhue5b9bff2018-05-20 17:40:03 -040046}
47
Hao Zhuad4ea392020-08-10 01:24:50 -040048#' HTML dependency for lightable
49#'
50#' @export
51html_dependency_lightable <- function() {
52 htmlDependency(name = "lightable",
53 version = "0.0.1",
54 src = system.file("lightable-0.0.1",
55 package = "kableExtra"),
56 stylesheet = "lightable.css")
57}
58
Hao Zhue5b9bff2018-05-20 17:40:03 -040059#' @export
Hao Zhuc8306792018-01-11 12:34:35 -050060knit_print.kableExtra <- function(x, ...) {
Hao Zhueaef4312018-01-10 17:05:23 -050061 x <- paste0(x, "\n\n")
Hao Zhuc1450882018-10-03 17:56:26 -040062 kp_dependency <- getOption("kableExtra.knit_print.dependency",
63 default = TRUE)
64 if (kp_dependency) {
65 meta_list <- list(html_dependency_kePrint())
Hao Zhuad4ea392020-08-10 01:24:50 -040066 meta_list[[2]] <- html_dependency_lightable()
Hao Zhuc1450882018-10-03 17:56:26 -040067 bs <- getOption("kableExtra.html.bsTable", default = FALSE)
68 if (bs) {
Hao Zhuad4ea392020-08-10 01:24:50 -040069 meta_list[[3]] <- html_dependency_bsTable()
Hao Zhuc1450882018-10-03 17:56:26 -040070 }
71 } else {
72 meta_list <- NULL
Hao Zhue5b9bff2018-05-20 17:40:03 -040073 }
74 asis_output(x, meta = meta_list)
Hao Zhueaef4312018-01-10 17:05:23 -050075}
76
77
78
79
Hao Zhu9410a272020-08-03 01:11:47 -040080
81