Now all element node attributes have to be threaded through the eph.attributes which is done by the garnish function.
52 lines
1.3 KiB
Elixir
52 lines
1.3 KiB
Elixir
defmodule OutlookWeb.HtmlDocComponent do
|
|
|
|
use Phoenix.Component
|
|
# use OutlookWeb, :html
|
|
import OutlookWeb.CoreComponents
|
|
import Phoenix.HTML
|
|
|
|
alias Phoenix.LiveView.JS
|
|
|
|
attr :tree, :list, required: true
|
|
|
|
def render_doc(%{tunit_tag: _} = assigns) do
|
|
~H"""
|
|
<.dnode :for={node <- @tree} node={node} tunit_tag={@tunit_tag} />
|
|
"""
|
|
end
|
|
def render_doc(assigns) do
|
|
assigns
|
|
|> Map.put(:tunit_tag, "span")
|
|
|> render_doc()
|
|
end
|
|
|
|
def dnode(%{node: %{status: status}} = assigns) do
|
|
~H"""
|
|
<.dynamic_tag name={@tunit_tag} nid={@node.nid} {Map.get(@node.eph, :attributes, %{})}
|
|
><%= @node.content |> raw %></.dynamic_tag>
|
|
"""
|
|
end
|
|
|
|
def dnode(assigns) when assigns.node.name == "img" do
|
|
~H"""
|
|
<img {@node.attributes |> Map.merge(Map.get(@node.eph, :attributes, %{})) |> Map.merge(%{nid: @node.nid})}>
|
|
"""
|
|
end
|
|
|
|
def dnode(assigns) when assigns.node.type == :element do
|
|
~H"""
|
|
<.dynamic_tag name={@node.name} nid={@node.nid} {Map.get(@node.eph, :attributes, %{})}
|
|
><.dnode :for={child_node <- @node.content} node={child_node} tunit_tag={@tunit_tag}
|
|
/></.dynamic_tag>
|
|
"""
|
|
end
|
|
|
|
def dnode(assigns) when assigns.node.type == :text do
|
|
~H"<%= @node.content %>"
|
|
end
|
|
|
|
def dnode(assigns) when assigns.node.type == :comment do
|
|
~H"<!--<%= @node.content |> raw %>-->"
|
|
end
|
|
end
|