Browse Source

Bugfix for IJulia.display_dict (#54)

* Call IJulia.display_dict with invokelatest

This is required for using printing methods defined in the notebook.

* Remove invokelatest from IJulia.limitstringmime
pull/56/head
Takafumi Arakaki 7 years ago committed by Fredrik Ekre
parent
commit
87eb47da3f
  1. 6
      src/IJulia.jl
  2. 2
      src/Literate.jl
  3. 14
      test/runtests.jl

6
src/IJulia.jl

@ -56,16 +56,14 @@ function limitstringmime(mime::MIME, x)
if israwtext(mime, x) if israwtext(mime, x)
return String(x) return String(x)
else else
# show(IOContext(buf, :limit=>true, :color=>true), mime, x) show(IOContext(buf, :limit=>true, :color=>true), mime, x)
Base.invokelatest(show, IOContext(buf, :limit=>true, :color=>true), mime, x)
end end
else else
b64 = Base64EncodePipe(buf) b64 = Base64EncodePipe(buf)
if isa(x, Vector{UInt8}) if isa(x, Vector{UInt8})
write(b64, x) # x assumed to be raw binary data write(b64, x) # x assumed to be raw binary data
else else
# show(IOContext(b64, :limit=>true, :color=>true), mime, x) show(IOContext(b64, :limit=>true, :color=>true), mime, x)
Base.invokelatest(show, IOContext(b64, :limit=>true, :color=>true), mime, x)
end end
close(b64) close(b64)
end end

2
src/Literate.jl

@ -561,7 +561,7 @@ function execute_notebook(nb)
execute_result["output_type"] = "execute_result" execute_result["output_type"] = "execute_result"
execute_result["metadata"] = Dict() execute_result["metadata"] = Dict()
execute_result["execution_count"] = execution_count execute_result["execution_count"] = execution_count
dd = IJulia.display_dict(r) dd = Base.invokelatest(IJulia.display_dict, r)
# we need to split some mime types into vectors of lines instead of a single string # we need to split some mime types into vectors of lines instead of a single string
for mime in ("image/svg+xml", "text/html") for mime in ("image/svg+xml", "text/html")
if haskey(dd, mime) if haskey(dd, mime)

14
test/runtests.jl

@ -647,6 +647,20 @@ end
# verify that inputfile exists # verify that inputfile exists
@test_throws ArgumentError Literate.notebook("nonexistent.jl", outdir) @test_throws ArgumentError Literate.notebook("nonexistent.jl", outdir)
# world time problem with `IJulia.display_dict`
write(inputfile, """
struct VegaLiteRenderable end
Base.show(io::IO, ::MIME"application/vnd.vegalite.v2+json", ::VegaLiteRenderable) =
write(io, \"\"\"
{"encoding":{"x":{"field":"x","type":"quantitative"},"y":{"field":"y","type":"quantitative"}},"data":{"values":[{"x":1,"y":1},{"x":2,"y":3},{"x":3,"y":2}]},"mark":"point"}
\"\"\")
Base.Multimedia.istextmime(::MIME{Symbol("application/vnd.vegalite.v2+json")}) = true
VegaLiteRenderable()
""")
Literate.notebook(inputfile, outdir)
notebook = read(joinpath(outdir, "inputfile.ipynb"), String)
@test occursin("\"application/vnd.vegalite.v2+json\":", notebook)
end end
end end
end end

Loading…
Cancel
Save