Now, I’ve tried the following changes.
(WIP: Comparing JuliaDocs:master...kimikage:ansicolor · JuliaDocs/Documenter.jl · GitHub)
- add a field / argument
ansicolor to User / makedocs().
- add a keyword argument
ansicolor in the @example block to override the user.ansicolor.
- add a
context keyword argument to Utilities.display_dict().
function limitstringmime(m::MIME"text/plain", x; context=nothing)
io = IOBuffer()
ioc = IOContext(context === nothing ? io : IOContext(io, context), :limit => true)
show(ioc, m, x)
return String(take!(io))
end
function display_dict(x; context=nothing)
out = Dict{MIME,Any}()
x === nothing && return out
# Always generate text/plain
out[MIME"text/plain"()] = limitstringmime(MIME"text/plain"(), x, context=context)
for m in [MIME"text/html"(), MIME"image/svg+xml"(), MIME"image/png"(),
MIME"image/webp"(), MIME"image/gif"(), MIME"image/jpeg"(),
MIME"text/latex"(), MIME"text/markdown"()]
showable(m, x) && (out[m] = stringmime(m, x, context=context))
end
return out
end
- in
Selectors.runner(::Type{ExampleBlocks}, x, page, doc), call:
output = Base.invokelatest(Utilities.display_dict, result, context=:color => ansicolor)
- in
HTMLWriter.mdconvert(), use AnsiColoredPrinters.HTMLPrinter:
...
elseif haskey(d, MIME"text/plain"())
input = IOBuffer(d[MIME"text/plain"()])
printer = AnsiColoredPrinters.HTMLPrinter(input, root_class="documenter-example-output")
out = Documents.RawHTML(repr(MIME"text/html"(), printer))
...
The changes successfully colorize lazy-printing objects.
However, the stdout output does not have ANSI escape codes.
What should I do after that? In the meantime, should I submit a WIP PR?
cc: @mortenpi
BTW, which setting of which SASS/SCSS compiler should I use?