TP-traitement-audio-visuel/julia/export_html.jl
2024-09-07 13:44:56 +02:00

43 lines
1 KiB
Julia

using Pluto
function export_html(notebook_path, html_path)
# load notebook
notebook = Pluto.load_notebook(Pluto.tamepath(notebook_path));
topology = Pluto.updated_topology(notebook.topology, notebook, notebook.cells)
# create offline workspace
workspace = Pluto.WorkspaceManager.make_workspace(
(
Pluto.ServerSession(),
notebook,
),
is_offline_renderer=true,
)
# run all the cells of the notebook
for cell in notebook.cells
Pluto.run_single!(
workspace,
cell,
topology.nodes[cell],
topology.codes[cell],
)
end
# convert notebook outputs to html
html_contents = Pluto.generate_html(notebook);
# write to html file
open(html_path, "w") do html_file
write(html_file, html_contents);
end
end
# get cli args
for arg in ARGS
filename, _ = splitext(arg)
html_path = filename * ".html"
println("Exporting $arg to $html_path")
export_html(arg, filename * ".html")
end