|
|
|
@ -641,47 +641,60 @@ function execute_markdown!(io::IO, sb::Module, block::String, outputdir; |
|
|
|
flavor::AbstractFlavor, image_formats::Vector, file_prefix::String, |
|
|
|
flavor::AbstractFlavor, image_formats::Vector, file_prefix::String, |
|
|
|
softscope::Bool) |
|
|
|
softscope::Bool) |
|
|
|
# TODO: Deal with explicit display(...) calls |
|
|
|
# TODO: Deal with explicit display(...) calls |
|
|
|
r, str, _ = execute_block(sb, block; inputfile=inputfile, fake_source=fake_source, softscope=softscope) |
|
|
|
r, str, display_dicts = execute_block(sb, block; inputfile=inputfile, fake_source=fake_source, softscope=softscope) |
|
|
|
|
|
|
|
|
|
|
|
# issue #101: consecutive codefenced blocks need newline |
|
|
|
# issue #101: consecutive codefenced blocks need newline |
|
|
|
# issue #144: quadruple backticks allow for triple backticks in the output |
|
|
|
# issue #144: quadruple backticks allow for triple backticks in the output |
|
|
|
plain_fence = "\n````\n" => "\n````" |
|
|
|
plain_fence = "\n````\n" => "\n````" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Any explicit calls to display(...) |
|
|
|
|
|
|
|
for dict in display_dicts |
|
|
|
|
|
|
|
for (mime, data) in dict |
|
|
|
|
|
|
|
display_markdown(io, data, outputdir, flavor, image_formats, file_prefix, plain_fence) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
if r !== nothing && !REPL.ends_with_semicolon(block) |
|
|
|
if r !== nothing && !REPL.ends_with_semicolon(block) |
|
|
|
|
|
|
|
display_markdown(io, r, outputdir, flavor, image_formats, file_prefix, plain_fence) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
elseif !isempty(str) |
|
|
|
|
|
|
|
write(io, plain_fence.first, str, plain_fence.second, '\n') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function display_markdown(io, data, outputdir, flavor, image_formats, file_prefix, plain_fence) |
|
|
|
if (flavor isa FranklinFlavor || flavor isa DocumenterFlavor) && |
|
|
|
if (flavor isa FranklinFlavor || flavor isa DocumenterFlavor) && |
|
|
|
Base.invokelatest(showable, MIME("text/html"), r) |
|
|
|
Base.invokelatest(showable, MIME("text/html"), data) |
|
|
|
htmlfence = flavor isa FranklinFlavor ? ("~~~" => "~~~") : ("```@raw html" => "```") |
|
|
|
htmlfence = flavor isa FranklinFlavor ? ("~~~" => "~~~") : ("```@raw html" => "```") |
|
|
|
write(io, "\n", htmlfence.first, "\n") |
|
|
|
write(io, "\n", htmlfence.first, "\n") |
|
|
|
Base.invokelatest(show, io, MIME("text/html"), r) |
|
|
|
Base.invokelatest(show, io, MIME("text/html"), data) |
|
|
|
write(io, "\n", htmlfence.second, "\n") |
|
|
|
write(io, "\n", htmlfence.second, "\n") |
|
|
|
return |
|
|
|
return |
|
|
|
end |
|
|
|
end |
|
|
|
for (mime, ext) in image_formats |
|
|
|
for (mime, ext) in image_formats |
|
|
|
if Base.invokelatest(showable, mime, r) |
|
|
|
if Base.invokelatest(showable, mime, data) |
|
|
|
file = file_prefix * ext |
|
|
|
file = file_prefix * ext |
|
|
|
open(joinpath(outputdir, file), "w") do io |
|
|
|
open(joinpath(outputdir, file), "w") do io |
|
|
|
Base.invokelatest(show, io, mime, r) |
|
|
|
Base.invokelatest(show, io, mime, data) |
|
|
|
end |
|
|
|
end |
|
|
|
write(io, "\n") |
|
|
|
write(io, "\n") |
|
|
|
return |
|
|
|
return |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
if Base.invokelatest(showable, MIME("text/markdown"), r) |
|
|
|
if Base.invokelatest(showable, MIME("text/markdown"), data) |
|
|
|
write(io, '\n') |
|
|
|
write(io, '\n') |
|
|
|
Base.invokelatest(show, io, MIME("text/markdown"), r) |
|
|
|
Base.invokelatest(show, io, MIME("text/markdown"), data) |
|
|
|
write(io, '\n') |
|
|
|
write(io, '\n') |
|
|
|
return |
|
|
|
return |
|
|
|
end |
|
|
|
end |
|
|
|
# fallback to text/plain |
|
|
|
# fallback to text/plain |
|
|
|
write(io, plain_fence.first) |
|
|
|
write(io, plain_fence.first) |
|
|
|
Base.invokelatest(show, io, "text/plain", r) |
|
|
|
Base.invokelatest(show, io, "text/plain", data) |
|
|
|
write(io, plain_fence.second, '\n') |
|
|
|
write(io, plain_fence.second, '\n') |
|
|
|
return |
|
|
|
return |
|
|
|
elseif !isempty(str) |
|
|
|
|
|
|
|
write(io, plain_fence.first, str, plain_fence.second, '\n') |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
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) |
|
|
|
|