forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rich.jl
28 lines (22 loc) · 700 Bytes
/
rich.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function tohtml(io::IO, m::MIME"text/html", x)
writemime(io, m, x)
end
function tohtml(io::IO, m::MIME"text/plain", x)
htmlesc(io, sprint(writemime, m, x))
end
function tohtml(io::IO, m::MIME"image/png", img)
print(io, """<img src="data:image/png;base64,""")
print(io, stringmime(m, img))
print(io, "\" />")
end
function tohtml(m::MIME"image/svg+xml", img)
writemime(io, m, img)
end
# Display infrastructure
function bestmime(val)
for mime in ("text/html", "image/svg+xml", "image/png", "text/plain")
mimewritable(mime, val) && return MIME(symbol(mime))
end
error("Cannot render $val to Markdown.")
end
tohtml(io::IO, x) = tohtml(io, bestmime(x), x)