Skip to content

Commit d5cc2e1

Browse files
committed
Print ANSI colors to HTML
1 parent e2b94a5 commit d5cc2e1

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/InferenceObjects.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module InferenceObjects
22

3+
using ANSIColoredPrinters: ANSIColoredPrinters
34
using Dates: Dates
45
using DimensionalData: DimensionalData, Dimensions, LookupArrays
56
using Random: Random

src/inference_data.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,20 @@ function Base.show(io::IO, ::MIME"text/plain", data::InferenceData)
193193
end
194194
function Base.show(io::IO, mime::MIME"text/html", data::InferenceData)
195195
show(io, mime, HTML("<div>InferenceData"))
196+
io_ansicolor = IOBuffer()
197+
ctx = IOContext(io_ansicolor, :compact => true, :color => true)
196198
for (name, group) in pairs(groups(data))
199+
show(ctx, MIME"text/plain"(), group)
200+
printer = ANSIColoredPrinters.HTMLPrinter(io_ansicolor)
197201
show(io, mime, HTML("""
198202
<details>
199203
<summary>$name</summary>
200-
<pre><code>$(sprint(show, "text/plain", group))</code></pre>
204+
"""))
205+
show(io, mime, printer)
206+
show(io, mime, HTML("""
201207
</details>
202208
"""))
209+
take!(io_ansicolor) # reset the buffer
203210
end
204211
return show(io, mime, HTML("</div>"))
205212
end

0 commit comments

Comments
 (0)