-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstyle.R
36 lines (33 loc) · 1.1 KB
/
style.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Knitr settings
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, autodep = TRUE)
options(crayon.enabled = TRUE)
# Knitr hooks
knitr::knit_hooks$set(
hide_button = function(before, options, envir) {
if (is.character(options$hide_button)) {
button_text = options$hide_button
} else {
button_text = "Show solution"
}
block_label <- paste0("hide_button", options$label)
if (before) {
return(paste0(sep = "\n",
'<button class="btn btn-danger" data-toggle="collapse" data-target="#', block_label, '"> ', button_text, ' </button>\n',
'<div id="', block_label, '" class="collapse">\n'))
} else {
return("</div><br />\n")
}
},
output = function(x, options){
x <- gsub(x, pattern = "<", replacement = "<")
x <- gsub(x, pattern = ">", replacement = ">")
paste0(
"<pre class=\"r-output\"><code>",
fansi::sgr_to_html(x = x, warn = TRUE, term.cap = "256"),
# ansistrings::ansi_to_html(text = x, fullpage = FALSE),
"</code></pre>"
)
}
)
# Display settings
options(width = 100)