|
|
|
@ -6,7 +6,7 @@ https://fredrikekre.github.io/Literate.jl/ for documentation. |
|
|
|
""" |
|
|
|
""" |
|
|
|
module Literate |
|
|
|
module Literate |
|
|
|
|
|
|
|
|
|
|
|
import JSON, REPL, IOCapture |
|
|
|
import JSON, REPL, IOCapture, Base64 |
|
|
|
|
|
|
|
|
|
|
|
include("IJulia.jl") |
|
|
|
include("IJulia.jl") |
|
|
|
import .IJulia |
|
|
|
import .IJulia |
|
|
|
@ -648,10 +648,8 @@ function execute_markdown!(io::IO, sb::Module, block::String, outputdir; |
|
|
|
plain_fence = "\n````\n" => "\n````" |
|
|
|
plain_fence = "\n````\n" => "\n````" |
|
|
|
|
|
|
|
|
|
|
|
# Any explicit calls to display(...) |
|
|
|
# Any explicit calls to display(...) |
|
|
|
for dict in display_dicts |
|
|
|
for (i, d) in enumerate(display_dicts) |
|
|
|
for (mime, data) in dict |
|
|
|
display_markdown_mime(io, d, outputdir, flavor, image_formats, "$(file_prefix)-$i", plain_fence) |
|
|
|
display_markdown(io, data, outputdir, flavor, image_formats, file_prefix, plain_fence) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if r !== nothing && !REPL.ends_with_semicolon(block) |
|
|
|
if r !== nothing && !REPL.ends_with_semicolon(block) |
|
|
|
@ -678,7 +676,7 @@ function display_markdown(io, data, outputdir, flavor, image_formats, file_prefi |
|
|
|
open(joinpath(outputdir, file), "w") do io |
|
|
|
open(joinpath(outputdir, file), "w") do io |
|
|
|
Base.invokelatest(show, io, mime, data) |
|
|
|
Base.invokelatest(show, io, mime, data) |
|
|
|
end |
|
|
|
end |
|
|
|
write(io, "\n") |
|
|
|
write(io, "\n\n") |
|
|
|
return |
|
|
|
return |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
@ -695,6 +693,52 @@ function display_markdown(io, data, outputdir, flavor, image_formats, file_prefi |
|
|
|
return |
|
|
|
return |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function display_markdown_mime(io, mime_dict, outputdir, flavor, image_formats, file_prefix, plain_fence) |
|
|
|
|
|
|
|
if (flavor isa FranklinFlavor || flavor isa DocumenterFlavor) && |
|
|
|
|
|
|
|
haskey(mime_dict, "text/html") |
|
|
|
|
|
|
|
htmlfence = flavor isa FranklinFlavor ? ("~~~" => "~~~") : ("```@raw html" => "```") |
|
|
|
|
|
|
|
data = mime_dict["text/html"] |
|
|
|
|
|
|
|
write(io, "\n", htmlfence.first, "\n") |
|
|
|
|
|
|
|
write(io, data) |
|
|
|
|
|
|
|
write(io, "\n", htmlfence.second, "\n") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (mime, ext) in image_formats |
|
|
|
|
|
|
|
if haskey(mime_dict, string(mime)) |
|
|
|
|
|
|
|
data = mime_dict[string(mime)] |
|
|
|
|
|
|
|
file = file_prefix * ext |
|
|
|
|
|
|
|
if istextmime(mime) |
|
|
|
|
|
|
|
write(joinpath(outputdir, file), data) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
data_decoded = Base64.base64decode(data) |
|
|
|
|
|
|
|
write(joinpath(outputdir, file), data_decoded) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
write(io, "\n\n") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if haskey(mime_dict, "text/latex") |
|
|
|
|
|
|
|
data = mime_dict["text/latex"] |
|
|
|
|
|
|
|
write(io, "\n```latex\n", data, "\n```\n") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if haskey(mime_dict, "text/markdown") |
|
|
|
|
|
|
|
data = mime_dict["text/markdown"] |
|
|
|
|
|
|
|
write(io, '\n', data, '\n') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# fallback to text/plain |
|
|
|
|
|
|
|
@assert haskey(mime_dict, "text/plain") |
|
|
|
|
|
|
|
write(io, plain_fence.first) |
|
|
|
|
|
|
|
write(io, mime_dict["text/plain"]) |
|
|
|
|
|
|
|
write(io, plain_fence.second, '\n') |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const JUPYTER_VERSION = v"4.3.0" |
|
|
|
const JUPYTER_VERSION = v"4.3.0" |
|
|
|
|
|
|
|
|
|
|
|
parse_nbmeta(line::Pair) = parse_nbmeta(line.second) |
|
|
|
parse_nbmeta(line::Pair) = parse_nbmeta(line.second) |
|
|
|
|