File tree Expand file tree Collapse file tree 5 files changed +2226
-429
lines changed Expand file tree Collapse file tree 5 files changed +2226
-429
lines changed Original file line number Diff line number Diff line change 1+ # nocov start - https://github.com/tidyverse/tibble/blob/master/R/fansi.R
2+ set_fansi_hooks <- function () {
3+ knitr :: opts_chunk $ set(collapse = TRUE )
4+
5+ if (Sys.getenv(" IN_GALLEY" ) != " " ) {
6+ knitr :: opts_chunk $ set(comment = " #>" )
7+ return ()
8+ }
9+
10+ knitr :: opts_chunk $ set(comment = pillar :: style_subtle(" #>" ))
11+
12+ options(cli.num_colors = 256 )
13+ options(pillar.bold = TRUE )
14+
15+ knitr :: knit_hooks $ set(
16+ output = colourise_chunk(" output" ),
17+ message = colourise_chunk(" message" ),
18+ warning = colourise_chunk(" warning" ),
19+ error = colourise_chunk(" error" )
20+ )
21+
22+ invisible ()
23+ }
24+
25+ colourise_chunk <- function (type ) {
26+ # Fallback if fansi is missing
27+ if (is_installed(" fansi" )) {
28+ sgr_to_html <- fansi :: sgr_to_html
29+ } else {
30+ sgr_to_html <- identity
31+ }
32+
33+ function (x , options ) {
34+ # lines <- strsplit(x, "\\n")[[1]]
35+ lines <- x
36+ if (type != " output" ) {
37+ lines <- crayon :: red(lines )
38+ }
39+ paste0(
40+ ' <div class="sourceCode"><pre class="sourceCode"><code class="sourceCode">' ,
41+ paste0(
42+ sgr_to_html(htmltools :: htmlEscape(lines )),
43+ collapse = " \n "
44+ ),
45+ " </code></pre></div>"
46+ )
47+ }
48+ }
49+ # nocov end
You can’t perform that action at this time.
0 commit comments