Skip to content

Commit

Permalink
use box horizontal marker for admonitions, and color them depending o…
Browse files Browse the repository at this point in the history
…n their title (JuliaLang#25627)
  • Loading branch information
KristofferC committed Jan 19, 2018
1 parent 0379a38 commit fe80431
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions base/markdown/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,38 @@ end
function term(io::IO, md::BlockQuote, columns)
s = sprint(term, md.content, columns - 10; context=io)
for line in split(rstrip(s), "\n")
println(io, " "^margin, "|", line)
println(io, " "^margin, "", line)
end
end

function term(io::IO, md::Admonition, columns)
print(io, " "^margin, "| ")
print_with_color(:bold, io, isempty(md.title) ? md.category : md.title)
println(io, "\n", " "^margin, "|")
col = :default
if lowercase(md.title) == "danger"
col = Base.error_color()
elseif lowercase(md.title) == "warning"
col = Base.warn_color()
elseif lowercase(md.title) in ("info", "note")
col = Base.info_color()
elseif lowercase(md.title) == "tip"
col = :green
end
print_with_color(col, io, " "^margin, ""; bold = true)
print_with_color(col, io, isempty(md.title) ? md.category : md.title; bold = true)
print_with_color(col, io, "\n", " "^margin, "", "\n"; bold = true)
s = sprint(term, md.content, columns - 10; context=io)
for line in split(rstrip(s), "\n")
println(io, " "^margin, "|", line)
print_with_color(col, io, " "^margin, ""; bold = true)
println(io, line)
end
end

function term(io::IO, f::Footnote, columns)
print(io, " "^margin, "| ")
print(io, " "^margin, " ")
print_with_color(:bold, io, "[^$(f.id)]")
println(io, "\n", " "^margin, "|")
println(io, "\n", " "^margin, "")
s = sprint(term, f.text, columns - 10; context=io)
for line in split(rstrip(s), "\n")
println(io, " "^margin, "|", line)
println(io, " "^margin, "", line)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ table = md"""
# mime output
let out =
@test sprint(show, "text/plain", book) ==
" Title\n ≡≡≡≡≡≡≡\n\n Some discussion\n\n | A quote\n\n Section important\n ===================\n\n Some bolded\n\n • list1\n \n • list2\n \n"
" Title\n ≡≡≡≡≡≡≡\n\n Some discussion\n\n A quote\n\n Section important\n ===================\n\n Some bolded\n\n • list1\n \n • list2\n \n"
@test sprint(show, "text/markdown", book) ==
"""
# Title
Expand Down

0 comments on commit fe80431

Please sign in to comment.