Skip to content

Commit

Permalink
Render md-only cells in safe preview mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Sep 19, 2023
1 parent 0e936c2 commit 67f8f4c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/evaluation/Run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,15 @@ function set_output!(cell::Cell, run, expr_cache::ExprAnalysisCache; persist_js_
cell.running = cell.queued = false
end

function clear_output!(cell::Cell)
cell.output = CellOutput()
cell.published_objects = Dict{String,Any}()

cell.runtime = nothing
cell.errored = false
cell.running = cell.queued = false
end

will_run_code(notebook::Notebook) = notebook.process_status ∈ (ProcessStatus.ready, ProcessStatus.starting)
will_run_pkg(notebook::Notebook) = notebook.process_status !== ProcessStatus.waiting_for_permission

Expand All @@ -349,6 +358,7 @@ function update_save_run!(
save::Bool=true,
run_async::Bool=false,
prerender_text::Bool=false,
clear_not_prerendered_cells::Bool=false,
auto_solve_multiple_defs::Bool=false,
on_auto_solve_multiple_defs::Function=identity,
kwargs...
Expand Down Expand Up @@ -393,7 +403,7 @@ function update_save_run!(
is_offline_renderer=true,
)

to_run_offline = filter(c -> !c.running && is_just_text(new, c) && is_just_text(old, c), cells)
to_run_offline = filter(c -> !c.running && is_just_text(new, c), cells)
for cell in to_run_offline
run_single!(offline_workspace, cell, new.nodes[cell], new.codes[cell])
end
Expand All @@ -402,6 +412,8 @@ function update_save_run!(
setdiff(cells, to_run_offline)
end

clear_not_prerendered_cells && foreach(clear_output!, to_run_online)

# this setting is not officially supported (default is `false`), so you can skip this block when reading the code
if !session.options.evaluation.run_notebook_on_load && prerender_text
# these cells do something like settings up an environment, we should always run them
Expand Down
8 changes: 6 additions & 2 deletions src/webserver/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,14 @@ responses[:run_multiple_cells] = function response_run_multiple_cells(πŸ™‹::Clie
putclientupdates!(πŸ™‹.session, πŸ™‹.initiator, UpdateMessage(:run_feedback, response, πŸ™‹.notebook, nothing, πŸ™‹.initiator))
end

# save=true fixes the issue where "Submit all changes" or `Ctrl+S` has no effect.
wfp = πŸ™‹.notebook.process_status == ProcessStatus.waiting_for_permission

update_save_run!(πŸ™‹.session, πŸ™‹.notebook, cells;
run_async=true, save=true,
auto_solve_multiple_defs=true, on_auto_solve_multiple_defs
auto_solve_multiple_defs=true, on_auto_solve_multiple_defs,
# special case: just render md cells in "Safe preview" mode
prerender_text=wfp,
clear_not_prerendered_cells=wfp,
)
end

Expand Down

0 comments on commit 67f8f4c

Please sign in to comment.