From 6c0bd2434cd211bf19a24509263cfa0fd56431ed Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Wed, 30 Jan 2019 21:42:47 -0800 Subject: [PATCH] Call IJulia.display_dict with invokelatest This is required for using printing methods defined in the notebook. --- src/Literate.jl | 2 +- test/runtests.jl | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Literate.jl b/src/Literate.jl index b3c753b..3f88641 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -561,7 +561,7 @@ function execute_notebook(nb) execute_result["output_type"] = "execute_result" execute_result["metadata"] = Dict() 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 for mime in ("image/svg+xml", "text/html") if haskey(dd, mime) diff --git a/test/runtests.jl b/test/runtests.jl index 48df58e..cfb39e3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -647,6 +647,20 @@ end # verify that inputfile exists @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