blob: 04e55c1aab9cd9c8477775bb0ef6017d7db1db3a [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"),
8 html_dependency_kePrint()
9 )
10 html_kable <- htmltools::browsable(
11 htmltools::HTML(
12 as.character(x),
13 '<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 -040014 )
Hao Zhud12f4832020-08-09 15:52:37 -040015 )
16 htmlDependencies(html_kable) <- dep
17 class(html_kable) <- "shiny.tag.list"
18 print(html_kable)
19 } else {
20 print(as.character(x))
21 }
Hao Zhueaef4312018-01-10 17:05:23 -050022}
23
Hao Zhu6107f372018-05-21 00:23:26 -040024#' HTML dependency for js script to enable bootstrap tooltip and popup message
25#'
Hao Zhue5b9bff2018-05-20 17:40:03 -040026#' @export
Hao Zhu8a69ad12018-01-10 18:01:41 -050027html_dependency_kePrint <- function() {
28 htmlDependency(name = "kePrint",
29 version = "0.0.1",
Hao Zhu7cb0e372018-01-10 18:29:30 -050030 src = system.file("kePrint-0.0.1",
Hao Zhu8a69ad12018-01-10 18:01:41 -050031 package = "kableExtra"),
32 script = "kePrint.js")
33}
Hao Zhueaef4312018-01-10 17:05:23 -050034
Hao Zhu6107f372018-05-21 00:23:26 -040035#' HTML dependency for Twitter bootstrap (table only)
36#'
Hao Zhueaef4312018-01-10 17:05:23 -050037#' @export
Hao Zhue5b9bff2018-05-20 17:40:03 -040038html_dependency_bsTable <- function() {
39 htmlDependency(name = "bsTable",
40 version = "3.3.7",
41 src = system.file("bootstrapTable-3.3.7",
42 package = "kableExtra"),
43 stylesheet = "bootstrapTable.min.css")
44}
45
46#' @export
Hao Zhuc8306792018-01-11 12:34:35 -050047knit_print.kableExtra <- function(x, ...) {
Hao Zhueaef4312018-01-10 17:05:23 -050048 x <- paste0(x, "\n\n")
Hao Zhuc1450882018-10-03 17:56:26 -040049 kp_dependency <- getOption("kableExtra.knit_print.dependency",
50 default = TRUE)
51 if (kp_dependency) {
52 meta_list <- list(html_dependency_kePrint())
53 bs <- getOption("kableExtra.html.bsTable", default = FALSE)
54 if (bs) {
55 meta_list[[2]] <- html_dependency_bsTable()
56 }
57 } else {
58 meta_list <- NULL
Hao Zhue5b9bff2018-05-20 17:40:03 -040059 }
60 asis_output(x, meta = meta_list)
Hao Zhueaef4312018-01-10 17:05:23 -050061}
62
63
64
65
Hao Zhu9410a272020-08-03 01:11:47 -040066
67