Repository: PumasAI/QuartoNotebookRunner.jl (julia)

Issue:
`engine: julia` does not show colors in the output
I noticed that using `engine: julia` the colors from the output are removed, but the same code with jupyer as the engine does show the colors. See this example: 

Jupyter version:

``````
---
title: "Evaluation with `jupyter: julia-1.11`"
format: html
jupyter: julia-1.11
---
```{julia}
using BenchmarkTools

@benchmark rand(100)
```

``````

Julia engine version: 

``````
---
title: "Evaluation with `engine:julia`"
format: html
engine: julia
julia:
  exeflags: [-tauto --project --color=yes]
---

```{julia}
using BenchmarkTools

@benchmark rand(100)
```

``````




<img width="738" alt="Image" src="https://github.com/user-attachments/assets/4176d1d6-70d2-4660-a6ca-327e5a611683" />

code:

Pull request description:
Fixes #249 by passing the process color setting to the `IOContext` that handles printing cell results.

The issue example now shows as below for me: <img width="841" alt="image" src="https://github.com/user-attachments/assets/ab1f6856-b9de-4169-b5fd-940ac0d1729a" />

@ajinkya-k if you're able to confirm this fixes it for you locally that would be great, thanks.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 117ef835..70e5c1c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 - QuartoNotebookRunner now corrects the png image size metadata it reports to quarto by the dpi stored in the file, if available. This will result in smaller visual image sizes for files with dpi > 96 [#248].
 
+### Fixed
+
+- Fix printing of cell results that contain color [#250]
+
 ## [v0.12.1] - 2025-02-04
 
 ### Fixed
@@ -346,3 +350,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 [#232]: https://github.com/PumasAI/QuartoNotebookRunner.jl/issues/232
 [#238]: https://github.com/PumasAI/QuartoNotebookRunner.jl/issues/238
 [#248]: https://github.com/PumasAI/QuartoNotebookRunner.jl/issues/248
+[#250]: https://github.com/PumasAI/QuartoNotebookRunner.jl/issues/250
diff --git a/src/QuartoNotebookWorker/src/render.jl b/src/QuartoNotebookWorker/src/render.jl
index 49c09031..fd152d12 100644
--- a/src/QuartoNotebookWorker/src/render.jl
+++ b/src/QuartoNotebookWorker/src/render.jl
@@ -269,6 +269,7 @@ function _io_context(cell_options = Dict{String,Any}())
     return [
         :module => NotebookState.notebook_module(),
         :limit => true,
+        :color => Base.have_color,
         # This allows a `show` method implementation to check for
         # metadata that may be of relevance to it's rendering. For
         # example, if a `typst` table is rendered with a caption


Test patch:
diff --git a/test/examples/stdout.qmd b/test/examples/stdout.qmd
index 0b37b885..57af18f3 100644
--- a/test/examples/stdout.qmd
+++ b/test/examples/stdout.qmd
@@ -29,4 +29,12 @@ Logging:
 
 ```{julia}
 @error "error text" value=3
-```
\ No newline at end of file
+```
+
+```{julia}
+struct Color
+    text::String
+end
+Base.show(io::IO, c::Color) = printstyled(io, c.text; color = :red)
+Color("red")
+```
diff --git a/test/testsets/stdout.jl b/test/testsets/stdout.jl
index 36608f37..6b5457f5 100644
--- a/test/testsets/stdout.jl
+++ b/test/testsets/stdout.jl
@@ -1,7 +1,7 @@
 include("../utilities/prelude.jl")
 
 test_example(joinpath(@__DIR__, "../examples/stdout.qmd")) do json
-    @test length(json["cells"]) == 12
+    @test length(json["cells"]) == 14
 
     cell = json["cells"][1]
     @test cell["cell_type"] == "markdown"
@@ -71,4 +71,7 @@ test_example(joinpath(@__DIR__, "../examples/stdout.qmd")) do json
     @test contains(cell["outputs"][1]["text"], "Error:")
     @test contains(cell["outputs"][1]["text"], "error text")
     @test contains(cell["outputs"][1]["text"], "value = 3")
+
+    cell = json["cells"][14]
+    @test cell["outputs"][1]["data"]["text/plain"] == "\e[31mred\e[39m"
 end