diff options
Diffstat (limited to 'sample_files/julia_1.jl')
-rw-r--r-- | sample_files/julia_1.jl | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/sample_files/julia_1.jl b/sample_files/julia_1.jl new file mode 100644 index 000000000..622c62c7a --- /dev/null +++ b/sample_files/julia_1.jl @@ -0,0 +1,49 @@ +import Base: display, redisplay + +struct InlineDisplay <: AbstractDisplay end + +# supported MIME types for inline display in IPython, in descending order +# of preference (descending "richness") +const ipy_mime = [ + "application/vnd.dataresource+json", + ["application/vnd.vegalite.v$n+json" for n in 3:-1:2]..., + ["application/vnd.vega.v$n+json" for n in 5:-1:3]..., + "application/vnd.plotly.v1+json", + "text/html", + "text/latex", + "image/svg+xml", + "image/png", + "image/jpeg", + "text/plain", + "text/markdown", + "application/javascript" +] + +# need special handling for showing a string as a textmime +# type, since in that case the string is assumed to be +# raw data unless it is text/plain +israwtext(::MIME, x::AbstractString) = true +israwtext(::MIME"text/plain", x::AbstractString) = false +israwtext(::MIME, x) = false + +# convert x to a string of type mime, making sure to use an +# IOContext that tells the underlying show function to limit output +function limitstringmime(mime::MIME, x) + buf = IOBuffer() + if istextmime(mime) + if israwtext(mime, x) + return String(x) + else + show(IOContext(buf, :limit=>true, :color=>true), mime, x) + end + else + b64 = Base64EncodePipe(buf) + if isa(x, Vector{UInt8}) + write(b64, x) # x assumed to be raw binary data + else + show(IOContext(b64, :limit=>true, :color=>true), mime, x) + end + close(b64) + end + return String(take!(buf)) +end |