2021-06-26 22:47:52 +08:00
|
|
|
defmodule LivebookWeb.Output.MarkdownComponent do
|
|
|
|
use LivebookWeb, :live_component
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def update(assigns, socket) do
|
|
|
|
socket = assign(socket, assigns)
|
|
|
|
|
|
|
|
{:ok,
|
2022-03-16 18:33:53 +08:00
|
|
|
push_event(socket, "markdown_renderer:#{socket.assigns.id}:content", %{
|
2021-06-26 22:47:52 +08:00
|
|
|
content: socket.assigns.content
|
|
|
|
})}
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
2021-07-07 20:32:49 +08:00
|
|
|
~H"""
|
2022-08-02 21:51:02 +08:00
|
|
|
<div
|
|
|
|
class="markdown"
|
2021-07-07 20:32:49 +08:00
|
|
|
id={"markdown-renderer-#{@id}"}
|
2021-06-26 22:47:52 +08:00
|
|
|
phx-hook="MarkdownRenderer"
|
2022-05-17 09:03:18 +08:00
|
|
|
data-id={@id}
|
2022-08-02 21:51:02 +08:00
|
|
|
data-session-path={Routes.session_path(@socket, :page, @session_id)}
|
|
|
|
>
|
2021-06-26 22:47:52 +08:00
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
end
|