Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions marimo/_runtime/output/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ def replace(value: object) -> None:
output = ctx.execution_context.output
output.clear()
if value is not None:
output.append(formatting.as_html(value))
write_internal(cell_id=ctx.execution_context.cell_id, value=value)
html = formatting.as_html(value)
output.append(html)
write_internal(cell_id=ctx.execution_context.cell_id, value=html)
else:
write_internal(cell_id=ctx.execution_context.cell_id, value=value)


@mddoc
Expand Down
24 changes: 24 additions & 0 deletions tests/_runtime/output/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ async def test_mutating_appended_outputs(
assert "after" in outputs[1]


async def test_replace_formats_output_once(
mocked_kernel: MockedKernel, exec_req: ExecReqProvider
) -> None:
await mocked_kernel.k.run(
[
exec_req.get(
"""
import marimo as mo

class Probe:
count = 0

def _repr_html_(self):
Probe.count += 1
return f"<div>formatted {Probe.count}</div>"

mo.output.replace(Probe())
assert Probe.count == 1
"""
)
]
)


async def test_nested_output(
mocked_kernel: MockedKernel, exec_req: ExecReqProvider
) -> None:
Expand Down
Loading