From 3980541e878ec3a88bb66caf2cf942e677c3c7bc Mon Sep 17 00:00:00 2001 From: Fredrik Ekre Date: Fri, 21 Aug 2020 10:14:55 +0200 Subject: [PATCH] Factor out code for Jupyter notebook output. --- src/Literate.jl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Literate.jl b/src/Literate.jl index 93ae390..4d118d0 100644 --- a/src/Literate.jl +++ b/src/Literate.jl @@ -529,6 +529,14 @@ function notebook(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...) preprocessor(inputfile, outputdir; user_config=config, user_kwargs=kwargs, type=:nb) # create the notebook + nb = jupyter_notebook(chunks, config) + + # write to file + outputfile = write_result(nb, config; print = (io, c)->JSON.print(io, c, 1)) + return outputfile +end + +function jupyter_notebook(chunks, config) nb = Dict() nb["nbformat"] = JUPYTER_VERSION.major nb["nbformat_minor"] = JUPYTER_VERSION.minor @@ -584,18 +592,16 @@ function notebook(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...) if config["execute"]::Bool @info "executing notebook `$(config["name"] * ".ipynb")`" try - cd(outputdir) do + cd(config["literate_outputdir"]) do nb = execute_notebook(nb) end catch err - @error "error when executing notebook based on input file: `$(Base.contractuser(inputfile))`" + @error "error when executing notebook based on input file: " * + "`$(Base.contractuser(config["literate_inputfile"]))`" rethrow(err) end end - - # write to file - outputfile = write_result(nb, config; print = (io, c)->JSON.print(io, c, 1)) - return outputfile + return nb end function execute_notebook(nb)