Skip to content

Commit

Permalink
Merge pull request #6 from AtelierArith/terasaki/highlight-julia-prom…
Browse files Browse the repository at this point in the history
…pt-in-readme

Support highlighting `julia>` for gat(@doc ::Module)
  • Loading branch information
terasakisatoshi authored Dec 7, 2024
2 parents 5b26c92 + 0ba03e5 commit 7659424
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/TerminalGat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ julia> gat(@doc sin)
"""
function gat(md::Markdown.MD)
str = sprint(show, MIME"text/plain"(), md, context=:color => false)
io = IOBuffer()
open(pipeline(`$(gat_jll.gat()) --theme monokai --force-color --lang julia`), "w", io) do f
println(f, str)
buf = IOBuffer()
open(pipeline(`$(gat_jll.gat()) --theme monokai --force-color --lang julia`), "w", buf) do tmp
println(tmp, str)
end
# If docstring contains an example about REPL session, we color `julia` as red `38;5;197m` that is used in the original `gat` command.
colored_text = replace(String(take!(io)), "julia" => "\033[38;5;197mjulia\033[0m")
colored_text = String(take!(buf))
# gat(@doc TerminalGat)
colored_text = replace(colored_text, "julia>" => "\033[38;5;197mjulia>\033[0m")
# gat(@doc sin)
colored_text = replace(colored_text, "julia\e[0m\e[38;5;197m>\e[0m" => "\033[38;5;197mjulia>\033[0m")
display(colored_text)
print(colored_text)
end


"""
gess(filename::AbstractString)
Expand Down

0 comments on commit 7659424

Please sign in to comment.