|
|
|
@ -346,7 +346,7 @@ function create_configuration(inputfile; user_config, user_kwargs, type=nothing) |
|
|
|
cfg["softscope"] = type === (:nb) ? true : false # on for Jupyter notebooks |
|
|
|
cfg["softscope"] = type === (:nb) ? true : false # on for Jupyter notebooks |
|
|
|
cfg["keep_comments"] = false |
|
|
|
cfg["keep_comments"] = false |
|
|
|
cfg["execute"] = type === :md ? false : true |
|
|
|
cfg["execute"] = type === :md ? false : true |
|
|
|
cfg["allow_errors"] = false |
|
|
|
cfg["continue_on_error"] = false |
|
|
|
cfg["codefence"] = pick_codefence( |
|
|
|
cfg["codefence"] = pick_codefence( |
|
|
|
get(user_config, "flavor", cfg["flavor"]), |
|
|
|
get(user_config, "flavor", cfg["flavor"]), |
|
|
|
get(user_config, "execute", cfg["execute"]), |
|
|
|
get(user_config, "execute", cfg["execute"]), |
|
|
|
@ -434,7 +434,7 @@ Available options: |
|
|
|
output script. Only applicable for `Literate.script`. |
|
|
|
output script. Only applicable for `Literate.script`. |
|
|
|
- `execute` (default: `true` for notebook, `false` for markdown): Whether to execute and |
|
|
|
- `execute` (default: `true` for notebook, `false` for markdown): Whether to execute and |
|
|
|
capture the output. Only applicable for `Literate.notebook` and `Literate.markdown`. |
|
|
|
capture the output. Only applicable for `Literate.notebook` and `Literate.markdown`. |
|
|
|
- `allow_errors` (default: `false`): Whether to capture and display error messages. If |
|
|
|
- `continue_on_error` (default: `false`): Whether to capture and display error messages. If |
|
|
|
`true`, blocks that error will display the error message. If `false`, errors will be |
|
|
|
`true`, blocks that error will display the error message. If `false`, errors will be |
|
|
|
(re)thrown as is. Ignored when `execute == false`. |
|
|
|
(re)thrown as is. Ignored when `execute == false`. |
|
|
|
- `codefence` (default: `````"````@example \$(name)" => "````"````` for `DocumenterFlavor()` |
|
|
|
- `codefence` (default: `````"````@example \$(name)" => "````"````` for `DocumenterFlavor()` |
|
|
|
@ -625,7 +625,7 @@ function markdown(inputfile, outputdir=pwd(); config::AbstractDict=Dict(), kwarg |
|
|
|
image_formats=config["image_formats"], |
|
|
|
image_formats=config["image_formats"], |
|
|
|
file_prefix="$(config["name"])-$(chunknum)", |
|
|
|
file_prefix="$(config["name"])-$(chunknum)", |
|
|
|
softscope=config["softscope"], |
|
|
|
softscope=config["softscope"], |
|
|
|
allow_errors=config["allow_errors"], |
|
|
|
continue_on_error=config["continue_on_error"], |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
@ -644,10 +644,10 @@ end |
|
|
|
function execute_markdown!(io::IO, sb::Module, block::String, outputdir; |
|
|
|
function execute_markdown!(io::IO, sb::Module, block::String, outputdir; |
|
|
|
inputfile::String, fake_source::String, |
|
|
|
inputfile::String, fake_source::String, |
|
|
|
flavor::AbstractFlavor, image_formats::Vector, file_prefix::String, |
|
|
|
flavor::AbstractFlavor, image_formats::Vector, file_prefix::String, |
|
|
|
softscope::Bool, allow_errors::Bool) |
|
|
|
softscope::Bool, continue_on_error::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, |
|
|
|
r, str, _ = execute_block(sb, block; inputfile=inputfile, fake_source=fake_source, |
|
|
|
softscope=softscope, allow_errors=allow_errors) |
|
|
|
softscope=softscope, continue_on_error=continue_on_error) |
|
|
|
# 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````" |
|
|
|
@ -784,7 +784,7 @@ function jupyter_notebook(chunks, config) |
|
|
|
nb = execute_notebook(nb; inputfile=config["literate_inputfile"], |
|
|
|
nb = execute_notebook(nb; inputfile=config["literate_inputfile"], |
|
|
|
fake_source=config["literate_outputfile"], |
|
|
|
fake_source=config["literate_outputfile"], |
|
|
|
softscope=config["softscope"], |
|
|
|
softscope=config["softscope"], |
|
|
|
allow_errors=config["allow_errors"], |
|
|
|
continue_on_error=config["continue_on_error"], |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
catch err |
|
|
|
catch err |
|
|
|
@ -797,7 +797,7 @@ function jupyter_notebook(chunks, config) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
function execute_notebook(nb; inputfile::String, fake_source::String, softscope::Bool, |
|
|
|
function execute_notebook(nb; inputfile::String, fake_source::String, softscope::Bool, |
|
|
|
allow_errors=allow_errors) |
|
|
|
continue_on_error=continue_on_error) |
|
|
|
sb = sandbox() |
|
|
|
sb = sandbox() |
|
|
|
execution_count = 0 |
|
|
|
execution_count = 0 |
|
|
|
for cell in nb["cells"] |
|
|
|
for cell in nb["cells"] |
|
|
|
@ -807,7 +807,7 @@ function execute_notebook(nb; inputfile::String, fake_source::String, softscope: |
|
|
|
block = join(cell["source"]) |
|
|
|
block = join(cell["source"]) |
|
|
|
r, str, display_dicts = execute_block(sb, block; inputfile=inputfile, |
|
|
|
r, str, display_dicts = execute_block(sb, block; inputfile=inputfile, |
|
|
|
fake_source=fake_source, softscope=softscope, |
|
|
|
fake_source=fake_source, softscope=softscope, |
|
|
|
allow_errors=allow_errors) |
|
|
|
continue_on_error=continue_on_error) |
|
|
|
|
|
|
|
|
|
|
|
# str should go into stream |
|
|
|
# str should go into stream |
|
|
|
if !isempty(str) |
|
|
|
if !isempty(str) |
|
|
|
@ -890,7 +890,7 @@ 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; inputfile::String, fake_source::String, |
|
|
|
function execute_block(sb::Module, block::String; inputfile::String, fake_source::String, |
|
|
|
softscope::Bool, allow_errors::Bool) |
|
|
|
softscope::Bool, continue_on_error::Bool) |
|
|
|
@debug """execute_block($sb, block) |
|
|
|
@debug """execute_block($sb, block) |
|
|
|
``` |
|
|
|
``` |
|
|
|
$(block) |
|
|
|
$(block) |
|
|
|
@ -916,7 +916,7 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
popdisplay(disp) # IOCapture.capture has a try-catch so should always end up here |
|
|
|
popdisplay(disp) # IOCapture.capture has a try-catch so should always end up here |
|
|
|
if c.error && !allow_errors |
|
|
|
if c.error && !continue_on_error |
|
|
|
error(""" |
|
|
|
error(""" |
|
|
|
$(sprint(showerror, c.value)) |
|
|
|
$(sprint(showerror, c.value)) |
|
|
|
when executing the following code block from inputfile `$(Base.contractuser(inputfile))` |
|
|
|
when executing the following code block from inputfile `$(Base.contractuser(inputfile))` |
|
|
|
|