From 9d1767dd50100f9b7fcbe7bab3f938d21d62e01f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Wed, 15 Mar 2023 17:48:38 +0100 Subject: [PATCH] Add support for plain text output (#1790) --- lib/livebook/runtime.ex | 4 +++- lib/livebook_web/live/app_live.ex | 2 +- lib/livebook_web/live/output.ex | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/livebook/runtime.ex b/lib/livebook/runtime.ex index f1ef9f052..f9d8feb41 100644 --- a/lib/livebook/runtime.ex +++ b/lib/livebook/runtime.ex @@ -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 diff --git a/lib/livebook_web/live/app_live.ex b/lib/livebook_web/live/app_live.ex index 11fbb6043..2c286e769 100644 --- a/lib/livebook_web/live/app_live.ex +++ b/lib/livebook_web/live/app_live.ex @@ -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 diff --git a/lib/livebook_web/live/output.ex b/lib/livebook_web/live/output.ex index 6266f7229..b2c01ebbf 100644 --- a/lib/livebook_web/live/output.ex +++ b/lib/livebook_web/live/output.ex @@ -47,6 +47,14 @@ defmodule LivebookWeb.Output do """ end + defp render_output({:plain_text, text}, %{id: id}) do + assigns = %{id: id, text: text} + + ~H""" +
<%= @text %>
+ """ + end + defp render_output({:markdown, markdown}, %{id: id, session_id: session_id}) do live_component(Output.MarkdownComponent, id: id,