How do I tell R Markdown / knitr to respect crayon color codes? I have the following R Markdown report.
---
title: "MWE"
author: "Will Landau"
date: "11/20/2017"
output: html_document
---
```{r color}
message(crayon::make_style("green")("My green message."))
```
When I knit and render it, I see the output
## My green message.
but the text color is not green.
Use case: https://github.com/wlandau-lilly/drake/issues/164
This seems to work:
---
title: "MWE"
output: html_document
---
```{r color, echo = FALSE}
options(crayon.enabled = TRUE)
knitr::knit_hooks$set(message = function(x, options){
paste0(
"<pre class=\"r-output\"><code>",
ansistrings::ansi_to_html(text = x, fullpage = FALSE),
"</code></pre>"
)
})
message(crayon::make_style("green")("My green message."))
```
Markdown output:
---
title: "MWE"
output: html_document
---
<pre class="r-output"><code>
## <span style="color:#4e9a06">My green message.</span>
</code></pre>
One caveat: ansistrings is not released yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With