From 172c620bbe2da1dcb1c82ae413d8160379ce7bfe Mon Sep 17 00:00:00 2001 From: Johanni Brea Date: Fri, 25 Aug 2023 22:43:22 +0200 Subject: [PATCH 1/4] fix EmbeddableDisplay --- src/runner/PlutoRunner.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runner/PlutoRunner.jl b/src/runner/PlutoRunner.jl index bbd1800e00..f1e67a5236 100644 --- a/src/runner/PlutoRunner.jl +++ b/src/runner/PlutoRunner.jl @@ -2382,7 +2382,7 @@ function Base.show(io::IO, m::MIME"text/html", e::EmbeddableDisplay) // see https://plutocon2021-demos.netlify.app/fonsp%20%E2%80%94%20javascript%20inside%20pluto to learn about the techniques used in this script - const body = $(publish_to_js(body, e.script_id)); + const body = $(PublishedToJavascript(body)); const mime = "$(string(mime))"; const create_new = this == null || this._mime !== mime; From 7829d4c0ff1777e7df3dc787d42d0130bf9ca487 Mon Sep 17 00:00:00 2001 From: Johanni Brea Date: Sat, 26 Aug 2023 16:15:57 +0200 Subject: [PATCH 2/4] pass cell_id to logs --- frontend/components/Cell.js | 2 +- frontend/components/Logs.js | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/frontend/components/Cell.js b/frontend/components/Cell.js index b43b843ae2..e1288a2266 100644 --- a/frontend/components/Cell.js +++ b/frontend/components/Cell.js @@ -337,7 +337,7 @@ export const Cell = ({ onerror=${remount} /> ${show_logs && cell_api_ready - ? html`<${Logs} logs=${Object.values(logs)} line_heights=${line_heights} set_cm_highlighted_line=${set_cm_highlighted_line} />` + ? html`<${Logs} cell_id=${cell_id} logs=${Object.values(logs)} line_heights=${line_heights} set_cm_highlighted_line=${set_cm_highlighted_line} />` : null} <${RunArea} cell_id=${cell_id} diff --git a/frontend/components/Logs.js b/frontend/components/Logs.js index 950b909680..c257a5aebb 100644 --- a/frontend/components/Logs.js +++ b/frontend/components/Logs.js @@ -20,7 +20,7 @@ const is_stdout_log = (log) => { return log.level == STDOUT_LOG_LEVEL } -export const Logs = ({ logs, line_heights, set_cm_highlighted_line }) => { +export const Logs = ({ cell_id, logs, line_heights, set_cm_highlighted_line }) => { const progress_logs = logs.filter(is_progress_log) const latest_progress_logs = progress_logs.reduce((progress_logs, log) => ({ ...progress_logs, [log.id]: log }), {}) const stdout_log = logs.reduce((stdout_log, log) => { @@ -59,6 +59,7 @@ export const Logs = ({ logs, line_heights, set_cm_highlighted_line }) => { } const dot = (log, i) => html`<${Dot} + cell_id=${cell_id} set_cm_highlighted_line=${set_cm_highlighted_line} level=${log.level} msg=${log.msg} @@ -97,9 +98,9 @@ const Progress = ({ progress }) => { return html`${Math.ceil(100 * progress)}%` } -const mimepair_output = (pair) => html`<${SimpleOutputBody} cell_id=${"adsf"} mime=${pair[1]} body=${pair[0]} persist_js_state=${false} />` +const mimepair_output = (cell_id, pair) => html`<${SimpleOutputBody} cell_id=${cell_id} mime=${pair[1]} body=${pair[0]} persist_js_state=${false} />` -const Dot = ({ set_cm_highlighted_line, msg, kwargs, y, level }) => { +const Dot = ({ cell_id, set_cm_highlighted_line, msg, kwargs, y, level }) => { const is_progress = is_progress_log({ level, kwargs }) const is_stdout = level === STDOUT_LOG_LEVEL let progress = null @@ -139,8 +140,8 @@ const Dot = ({ set_cm_highlighted_line, msg, kwargs, y, level }) => { >`} /> <${LogViewAnsiUp} value=${msg[0]} />` - : html`${mimepair_output(msg)}${kwargs.map( - ([k, v]) => html`${k}${mimepair_output(v)}` + : html`${mimepair_output(cell_id, msg)}${kwargs.map( + ([k, v]) => html`${k}${mimepair_output(cell_id, v)}` )}`} ` From c49930f20db1f8994b4bb905ba4205b5d19f9584 Mon Sep 17 00:00:00 2001 From: Johanni Brea Date: Sat, 26 Aug 2023 16:46:01 +0200 Subject: [PATCH 3/4] Revert "pass cell_id to logs" This reverts commit 7829d4c0ff1777e7df3dc787d42d0130bf9ca487. --- frontend/components/Cell.js | 2 +- frontend/components/Logs.js | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/frontend/components/Cell.js b/frontend/components/Cell.js index e1288a2266..b43b843ae2 100644 --- a/frontend/components/Cell.js +++ b/frontend/components/Cell.js @@ -337,7 +337,7 @@ export const Cell = ({ onerror=${remount} /> ${show_logs && cell_api_ready - ? html`<${Logs} cell_id=${cell_id} logs=${Object.values(logs)} line_heights=${line_heights} set_cm_highlighted_line=${set_cm_highlighted_line} />` + ? html`<${Logs} logs=${Object.values(logs)} line_heights=${line_heights} set_cm_highlighted_line=${set_cm_highlighted_line} />` : null} <${RunArea} cell_id=${cell_id} diff --git a/frontend/components/Logs.js b/frontend/components/Logs.js index c257a5aebb..950b909680 100644 --- a/frontend/components/Logs.js +++ b/frontend/components/Logs.js @@ -20,7 +20,7 @@ const is_stdout_log = (log) => { return log.level == STDOUT_LOG_LEVEL } -export const Logs = ({ cell_id, logs, line_heights, set_cm_highlighted_line }) => { +export const Logs = ({ logs, line_heights, set_cm_highlighted_line }) => { const progress_logs = logs.filter(is_progress_log) const latest_progress_logs = progress_logs.reduce((progress_logs, log) => ({ ...progress_logs, [log.id]: log }), {}) const stdout_log = logs.reduce((stdout_log, log) => { @@ -59,7 +59,6 @@ export const Logs = ({ cell_id, logs, line_heights, set_cm_highlighted_line }) = } const dot = (log, i) => html`<${Dot} - cell_id=${cell_id} set_cm_highlighted_line=${set_cm_highlighted_line} level=${log.level} msg=${log.msg} @@ -98,9 +97,9 @@ const Progress = ({ progress }) => { return html`${Math.ceil(100 * progress)}%` } -const mimepair_output = (cell_id, pair) => html`<${SimpleOutputBody} cell_id=${cell_id} mime=${pair[1]} body=${pair[0]} persist_js_state=${false} />` +const mimepair_output = (pair) => html`<${SimpleOutputBody} cell_id=${"adsf"} mime=${pair[1]} body=${pair[0]} persist_js_state=${false} />` -const Dot = ({ cell_id, set_cm_highlighted_line, msg, kwargs, y, level }) => { +const Dot = ({ set_cm_highlighted_line, msg, kwargs, y, level }) => { const is_progress = is_progress_log({ level, kwargs }) const is_stdout = level === STDOUT_LOG_LEVEL let progress = null @@ -140,8 +139,8 @@ const Dot = ({ cell_id, set_cm_highlighted_line, msg, kwargs, y, level }) => { >`} /> <${LogViewAnsiUp} value=${msg[0]} />` - : html`${mimepair_output(cell_id, msg)}${kwargs.map( - ([k, v]) => html`${k}${mimepair_output(cell_id, v)}` + : html`${mimepair_output(msg)}${kwargs.map( + ([k, v]) => html`${k}${mimepair_output(v)}` )}`} ` From 238958d11e7814977860fd4242e42a484bd064bd Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 27 Aug 2023 16:00:12 +0200 Subject: [PATCH 4/4] Add test for `embed_display` --- test/RichOutput.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/RichOutput.jl b/test/RichOutput.jl index 1132472112..69e1eccff9 100644 --- a/test/RichOutput.jl +++ b/test/RichOutput.jl @@ -229,6 +229,21 @@ import Pluto: update_run!, WorkspaceManager, ClientSession, ServerSession, Noteb end end + @testset "embed_display" begin + 🍭.options.evaluation.workspace_use_distributed = false + notebook = Notebook([ + Cell("x = randn(10)"), + Cell(raw"md\"x = $(embed_display(x))\"") + ]) + update_run!(🍭, notebook, notebook.cells) + + @test notebook.cells[1] |> noerror + @test notebook.cells[2] |> noerror + + @test notebook.cells[2].output.body isa String + @test occursin("getPublishedObject", notebook.cells[2].output.body) + end + @testset "Table viewer" begin 🍭.options.evaluation.workspace_use_distributed = true notebook = Notebook([