diff --git a/Project.toml b/Project.toml index 49d96e154c..67f8c61bd5 100644 --- a/Project.toml +++ b/Project.toml @@ -9,6 +9,7 @@ Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" FileWatching = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" diff --git a/src/notebookserver/Notebook.jl b/src/notebookserver/Notebook.jl index c4be2dc586..f586b07b35 100644 --- a/src/notebookserver/Notebook.jl +++ b/src/notebookserver/Notebook.jl @@ -43,8 +43,11 @@ function save_notebook(io, notebook::Notebook) # Anything between the version string and the first UUID delimiter will be ignored by the notebook loader. println(io, "") println(io, "using Markdown") + println(io, "using InteractiveUtils") # Super Advanced Code Analysis™ to add the @bind macro to the saved file if it's used somewhere. if any(occursin("@bind", c.code) for c in notebook.cells) + println(io, "") + println(io, "# This Pluto notebook uses @bind for interactivity. When running this notebook outside of Pluto, the following 'mock version' of @bind gives bound variables a default value (instead of an error).") println(io, PlutoRunner.fake_bind) end println(io) diff --git a/src/react/WorkspaceManager.jl b/src/react/WorkspaceManager.jl index 6aabbacc24..a7a162d820 100644 --- a/src/react/WorkspaceManager.jl +++ b/src/react/WorkspaceManager.jl @@ -19,7 +19,7 @@ end "These expressions get evaluated inside every newly create module inside a `Workspace`." const workspace_preamble = [ - :(using Markdown, Main.PlutoRunner), + :(using Markdown, InteractiveUtils, Main.PlutoRunner), :(ENV["GKSwstype"] = "nul"), :(show, showable, showerror, repr, string, print, println), # https://github.com/JuliaLang/julia/issues/18181 ] @@ -37,7 +37,7 @@ workspaces = Dict{UUID,Workspace}() """Create a workspace for the notebook, optionally in a separate process. `new_process`: Should future workspaces be created on a separate process (`true`) or on the same one (`false`)? Only workspaces on a separate process can be stopped during execution. Windows currently supports `true` only partially: you can't stop cells on Windows. _Defaults to `ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"]`_""" -function make_workspace(notebook::Notebook, new_process = (ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] == "true"))::Workspace +function make_workspace(notebook::Notebook, new_process=(ENV["PLUTO_WORKSPACE_USE_DISTRIBUTED"] == "true"))::Workspace pid = if new_process create_workspaceprocess() else @@ -115,11 +115,11 @@ end "Evaluate expression inside the workspace - output is fetched and formatted, errors are caught and formatted. Returns formatted output and error flags. `expr` has to satisfy `ExploreExpression.is_toplevel_expr`." -function eval_fetch_in_workspace(notebook::Notebook, expr::Expr, cell_id::UUID, ends_with_semicolon::Bool=false)::NamedTuple{(:output_formatted, :errored, :interrupted, :runtime),Tuple{Tuple{String,MIME},Bool,Bool,Union{UInt64, Missing}}} +function eval_fetch_in_workspace(notebook::Notebook, expr::Expr, cell_id::UUID, ends_with_semicolon::Bool=false)::NamedTuple{(:output_formatted, :errored, :interrupted, :runtime),Tuple{Tuple{String,MIME},Bool,Bool,Union{UInt64,Missing}}} eval_fetch_in_workspace(get_workspace(notebook), expr, cell_id, ends_with_semicolon) end -function eval_fetch_in_workspace(workspace::Workspace, expr::Expr, cell_id::UUID, ends_with_semicolon::Bool=false)::NamedTuple{(:output_formatted, :errored, :interrupted, :runtime),Tuple{Tuple{String,MIME},Bool,Bool,Union{UInt64, Missing}}} +function eval_fetch_in_workspace(workspace::Workspace, expr::Expr, cell_id::UUID, ends_with_semicolon::Bool=false)::NamedTuple{(:output_formatted, :errored, :interrupted, :runtime),Tuple{Tuple{String,MIME},Bool,Bool,Union{UInt64,Missing}}} # We wrap the expression in a try-catch block, because we want to capture and format the exception on the worker itself. wrapped = trycatch_expr(expr, workspace.module_name, cell_id) diff --git a/test/Notebook.jl b/test/Notebook.jl index 047de56b88..3e8281b6f2 100644 --- a/test/Notebook.jl +++ b/test/Notebook.jl @@ -13,6 +13,7 @@ function basic_notebook() Cell("💩 = :💩"), # ends with 4-byte character Cell("b = let\n\tx = a + a\n\tx*x\nend"), Cell("html\"
My name is kiki
\""), + # test included Markdown import Cell("""md"# Cześć! My name is **baba** and I like \$\\LaTeX\$ _support!_ @@ -24,6 +25,8 @@ function basic_notebook() ### The spectacle before us was indeed sublime. Apparently we had reached a great height in the atmosphere, for the sky was a dead black, and the stars had ceased to twinkle. By the same illusion which lifts the horizon of the sea to the level of the spectator on a hillside, the sable cloud beneath was dished out, and the car seemed to float in the middle of an immense dark sphere, whose upper half was strewn with silver. Looking down into the dark gulf below, I could see a ruddy light streaming through a rift in the clouds." """), + # test included InteractiveUtils import + Cell("subtypes(Number)"), ]) end diff --git a/test/runtests.jl b/test/runtests.jl index 501aee399f..1c797d0377 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,8 +1,8 @@ include("./helpers.jl") include("./ExploreExpression.jl") -include("./React.jl") include("./Notebook.jl") +include("./React.jl") include("./WorkspaceManager.jl") # TODO: test PlutoRunner functions like: