From e08ca0a19bd5e61dac778ddf4aaf6cef37532e48 Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 14 Aug 2020 00:18:08 +0200 Subject: [PATCH] Let markdown output capture output with the "text/markdown" MIME. --- src/Literate.jl | 6 ++++++ test/runtests.jl | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/Literate.jl b/src/Literate.jl index 2b1284a..516ebd2 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -469,6 +469,12 @@ function execute_markdown!(io::IO, sb::Module, block::String, outputdir) return end end + if showable(MIME("text/markdown"), r) + write(io, '\n') + Base.invokelatest(show, io, MIME("text/markdown"), r) + write(io, '\n') + return + end # fallback to text/plain write(io, plain_fence.first) Base.invokelatest(show, io, "text/plain", r) diff --git a/test/runtests.jl b/test/runtests.jl index 93ec031..7553606 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -663,6 +663,10 @@ end end Base.show(io::IO, mime::MIME"image/jpeg", ::JPEG) = print(io, "JPEG") JPEG() #- + struct MD end + Base.show(io::IO, mime::MIME"text/markdown", ::MD) = print(io, "# " * "MD") + MD() + #- print("hello"); print(stdout, ", "); print(stderr, "world") #- print("hej, världen") @@ -681,6 +685,7 @@ end end @test occursin("```\n2×2 $(Matrix{Int}):\n 1 2\n 3 4\n```", markdown) # text/plain @test occursin(r"!\[\]\(\d+\.png\)", markdown) # image/png @test occursin(r"!\[\]\(\d+\.jpeg\)", markdown) # image/jpeg + @test occursin(r"# MD", markdown) # text/markdown @test occursin("```\nhello, world\n```", markdown) # stdout/stderr @test occursin("```\n42\n```", markdown) # result over stdout/stderr @test !occursin("246", markdown) # empty output because trailing ;