ANSI colours with downlit #3717
-
Does Quarto support ANSI colours in R output? This is handled by For example, in this reprex the output will just be plain text, but it should be coloured.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
I don't know the interaction between
|
Beta Was this translation helpful? Give feedback.
-
@mccarthy-m-g This is only working in pkgdown context right ? Or do you also get coloring working in R Markdown document ? cli does ANSI coloring, and not HTML coloring. So to make in work in a HTML rendered document, downlit is converting to HTML highlighting (with help of Also I believe pkgdown is doing a special post processing before downlit as ANSI escape character can be lost otherwise. All that above explain that this does not "just works" currently with Quarto. Can you confirm that it works for you only in pkgdown context ? From there, I'll know where to look to try improve this behavior. From my test, it does not work either in R Markdown, only in pkgdown special handling. By the fansi can be used directly to convert from ANSI with a knitr hooks. See https://github.com/brodieG/fansi#rmarkdown Example to illustrate how this works: ---
title: "Reprex"
format: html
---
```{r}
#| comment: ''
#| results: asis
#| echo: false
old_hook <- fansi::set_knit_hooks(knitr::knit_hooks, which = c("output", "warning", "error", "message"))
options(crayon.enabled = TRUE)
```
```{r}
cat(cli::col_red("This is red"), "\n")
cat(cli::col_blue("This is blue"), "\n")
message(cli::col_green("This is green"))
warning(cli::style_bold("This is bold"))
``` Hope it helps understand. But anyway, I'll think about how improving this with |
Beta Was this translation helpful? Give feedback.
@mccarthy-m-g This is only working in pkgdown context right ? Or do you also get coloring working in R Markdown document ?
cli does ANSI coloring, and not HTML coloring. So to make in work in a HTML rendered document, downlit is converting to HTML highlighting (with help of
fansi
📦. Moreover, I think by default cli function deactivate ANSI coloring in a knitting context. So it needs to be reactivated to be then handled by downlit.Also I believe pkgdown is doing a special post processing before downlit as ANSI escape character can be lost otherwise.
All that above explain that this does not "just works" currently wit…