defmodule LivebookWeb.Output.MarkdownComponent do use LivebookWeb, :live_component @impl true def mount(socket) do {:ok, socket |> assign(allowed_uri_schemes: Livebook.Config.allowed_uri_schemes(), initialized: false) |> stream(:chunks, [])} end @impl true def update(%{event: {:append, output}}, socket) do {:ok, append_text(socket, output.text)} end def update(assigns, socket) do {output, assigns} = Map.pop(assigns, :output) socket = assign(socket, assigns) if socket.assigns.initialized do # After initialization, output text may be pruned and updates # are sent as events instead {:ok, socket} else {:ok, socket |> append_text(output.text) |> assign(:initialized, true)} end end defp append_text(socket, text) do chunk = %{id: Livebook.Utils.random_long_id(), text: text} stream_insert(socket, :chunks, chunk) end @impl true def render(assigns) do ~H"""
""" end end