blob: 6d1c5343a5ccca7ea0d128564d5215b052d6c5f1 [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)
4 if (view_html) {
5 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),
14 '<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"),
44 stylesheet = "bootstrapTable.min.css")
45}
46
Hao Zhuad4ea392020-08-10 01:24:50 -040047#' HTML dependency for lightable
48#'
49#' @export
50html_dependency_lightable <- function() {
51 htmlDependency(name = "lightable",
52 version = "0.0.1",
53 src = system.file("lightable-0.0.1",
54 package = "kableExtra"),
55 stylesheet = "lightable.css")
56}
57
Hao Zhue5b9bff2018-05-20 17:40:03 -040058#' @export
Hao Zhuc8306792018-01-11 12:34:35 -050059knit_print.kableExtra <- function(x, ...) {
Hao Zhueaef4312018-01-10 17:05:23 -050060 x <- paste0(x, "\n\n")
Hao Zhuc1450882018-10-03 17:56:26 -040061 kp_dependency <- getOption("kableExtra.knit_print.dependency",
62 default = TRUE)
63 if (kp_dependency) {
64 meta_list <- list(html_dependency_kePrint())
Hao Zhuad4ea392020-08-10 01:24:50 -040065 meta_list[[2]] <- html_dependency_lightable()
Hao Zhuc1450882018-10-03 17:56:26 -040066 bs <- getOption("kableExtra.html.bsTable", default = FALSE)
67 if (bs) {
Hao Zhuad4ea392020-08-10 01:24:50 -040068 meta_list[[3]] <- html_dependency_bsTable()
Hao Zhuc1450882018-10-03 17:56:26 -040069 }
70 } else {
71 meta_list <- NULL
Hao Zhue5b9bff2018-05-20 17:40:03 -040072 }
73 asis_output(x, meta = meta_list)
Hao Zhueaef4312018-01-10 17:05:23 -050074}
75
76
77
78
Hao Zhu9410a272020-08-03 01:11:47 -040079
80