Skip to content

Commit

Permalink
Update Resource.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Nov 4, 2023
1 parent b7cd2cf commit 0cbd7b0
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Resource.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,24 @@ DownloadButton(data) = DownloadButton(data, "result")

function Base.show(io::IO, m::MIME"text/html", db::DownloadButton)
mime = mime_fromfilename(db.filename)
data = to_data(db.data, mime)
data = if db.data isa String || db.data isa AbstractVector{UInt8} || isnothing(mime)
db.data
else
repr(mime, db.data)
end

write(io, "<a href=\"data:")
write(io, string(!isnothing(mime) ? mime : ""))
write(io, ";base64,")
write(io, data)
write(io, Base64.base64encode(data))
write(io, "\" download=\"")
write(io, Markdown.htmlesc(db.filename))
write(io, "\" style=\"text-decoration: none; font-weight: normal; font-size: .75em; font-family: sans-serif;\"><button>Download...</button> ")
write(io, db.filename)
write(io, "</a>")
end

function to_data(object::Any, mime::Union{MIME, Nothing})::String
function downloadbutton_data(object::Any, mime::Union{MIME, Nothing})::String
data = if object isa String || object isa AbstractVector{UInt8} || isnothing(mime)
object
else
Expand Down

0 comments on commit 0cbd7b0

Please sign in to comment.