Add support for plain text output (#1790)

This commit is contained in:
Jonatan Kłosko 2023-03-15 17:48:38 +01:00 committed by GitHub
parent f172acca47
commit 9d1767dd50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 2 deletions

View file

@ -45,8 +45,10 @@ defprotocol Livebook.Runtime do
:ignored
# IO output, adjacent such outputs are treated as a whole
| {:stdout, binary()}
# Standalone text block
# Standalone text block otherwise matching :stdout
| {:text, binary()}
# Plain text content
| {:plain_text, binary()}
# Markdown content
| {:markdown, binary()}
# A raw image in the given format

View file

@ -251,7 +251,7 @@ defmodule LivebookWeb.AppLive do
end
defp filter_output({idx, output})
when elem(output, 0) in [:markdown, :image, :js, :control],
when elem(output, 0) in [:plain_text, :markdown, :image, :js, :control],
do: {idx, output}
defp filter_output({idx, {:tabs, outputs, metadata}}) do

View file

@ -47,6 +47,14 @@ defmodule LivebookWeb.Output do
"""
end
defp render_output({:plain_text, text}, %{id: id}) do
assigns = %{id: id, text: text}
~H"""
<div id={@id} class="text-gray-700"><%= @text %></div>
"""
end
defp render_output({:markdown, markdown}, %{id: id, session_id: session_id}) do
live_component(Output.MarkdownComponent,
id: id,