|
|
|
@ -458,7 +458,7 @@ function markdown(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...) |
|
|
|
write_code = !(all(l -> endswith(l, "#hide"), chunk.lines) && !(config["documenter"]::Bool)) |
|
|
|
write_code = !(all(l -> endswith(l, "#hide"), chunk.lines) && !(config["documenter"]::Bool)) |
|
|
|
write_code && write(iomd, seekstart(iocode)) |
|
|
|
write_code && write(iomd, seekstart(iocode)) |
|
|
|
if config["execute"]::Bool |
|
|
|
if config["execute"]::Bool |
|
|
|
execute_markdown!(iomd, sb, join(chunk.lines, '\n'), outputdir) |
|
|
|
execute_markdown!(iomd, sb, join(chunk.lines, '\n'), outputdir; inputfile=config["literate_inputfile"]) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
write(iomd, '\n') # add a newline between each chunk |
|
|
|
write(iomd, '\n') # add a newline between each chunk |
|
|
|
@ -472,9 +472,9 @@ function markdown(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...) |
|
|
|
return outputfile |
|
|
|
return outputfile |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function execute_markdown!(io::IO, sb::Module, block::String, outputdir) |
|
|
|
function execute_markdown!(io::IO, sb::Module, block::String, outputdir; inputfile::String="<unknown>") |
|
|
|
# TODO: Deal with explicit display(...) calls |
|
|
|
# TODO: Deal with explicit display(...) calls |
|
|
|
r, str, _ = execute_block(sb, block) |
|
|
|
r, str, _ = execute_block(sb, block; inputfile=inputfile) |
|
|
|
plain_fence = "\n```\n" => "\n```" # issue #101: consecutive codefenced blocks need newline |
|
|
|
plain_fence = "\n```\n" => "\n```" # issue #101: consecutive codefenced blocks need newline |
|
|
|
if r !== nothing && !REPL.ends_with_semicolon(block) |
|
|
|
if r !== nothing && !REPL.ends_with_semicolon(block) |
|
|
|
for (mime, ext) in [(MIME("image/png"), ".png"), (MIME("image/jpeg"), ".jpeg")] |
|
|
|
for (mime, ext) in [(MIME("image/png"), ".png"), (MIME("image/jpeg"), ".jpeg")] |
|
|
|
@ -601,7 +601,7 @@ function jupyter_notebook(chunks, config) |
|
|
|
@info "executing notebook `$(config["name"] * ".ipynb")`" |
|
|
|
@info "executing notebook `$(config["name"] * ".ipynb")`" |
|
|
|
try |
|
|
|
try |
|
|
|
cd(config["literate_outputdir"]) do |
|
|
|
cd(config["literate_outputdir"]) do |
|
|
|
nb = execute_notebook(nb) |
|
|
|
nb = execute_notebook(nb; inputfile=config["literate_inputfile"]) |
|
|
|
end |
|
|
|
end |
|
|
|
catch err |
|
|
|
catch err |
|
|
|
@error "error when executing notebook based on input file: " * |
|
|
|
@error "error when executing notebook based on input file: " * |
|
|
|
@ -612,7 +612,7 @@ function jupyter_notebook(chunks, config) |
|
|
|
return nb |
|
|
|
return nb |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function execute_notebook(nb) |
|
|
|
function execute_notebook(nb; inputfile::String="<unknown>") |
|
|
|
sb = sandbox() |
|
|
|
sb = sandbox() |
|
|
|
execution_count = 0 |
|
|
|
execution_count = 0 |
|
|
|
for cell in nb["cells"] |
|
|
|
for cell in nb["cells"] |
|
|
|
@ -620,7 +620,7 @@ function execute_notebook(nb) |
|
|
|
execution_count += 1 |
|
|
|
execution_count += 1 |
|
|
|
cell["execution_count"] = execution_count |
|
|
|
cell["execution_count"] = execution_count |
|
|
|
block = join(cell["source"]) |
|
|
|
block = join(cell["source"]) |
|
|
|
r, str, display_dicts = execute_block(sb, block) |
|
|
|
r, str, display_dicts = execute_block(sb, block; inputfile=inputfile) |
|
|
|
|
|
|
|
|
|
|
|
# str should go into stream |
|
|
|
# str should go into stream |
|
|
|
if !isempty(str) |
|
|
|
if !isempty(str) |
|
|
|
@ -702,7 +702,7 @@ function Base.display(ld::LiterateDisplay, mime::MIME, x) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# Execute a code-block in a module and capture stdout/stderr and the result |
|
|
|
# Execute a code-block in a module and capture stdout/stderr and the result |
|
|
|
function execute_block(sb::Module, block::String) |
|
|
|
function execute_block(sb::Module, block::String; inputfile::String="<unknown>") |
|
|
|
@debug """execute_block($sb, block) |
|
|
|
@debug """execute_block($sb, block) |
|
|
|
``` |
|
|
|
``` |
|
|
|
$(block) |
|
|
|
$(block) |
|
|
|
@ -724,7 +724,7 @@ function execute_block(sb::Module, block::String) |
|
|
|
if c.error |
|
|
|
if c.error |
|
|
|
error(""" |
|
|
|
error(""" |
|
|
|
$(sprint(showerror, c.value)) |
|
|
|
$(sprint(showerror, c.value)) |
|
|
|
when executing the following code block |
|
|
|
when executing the following code block in file `$(Base.contractuser(inputfile))` |
|
|
|
|
|
|
|
|
|
|
|
```julia |
|
|
|
```julia |
|
|
|
$block |
|
|
|
$block |
|
|
|
|