Add importing html and save it to Article
Additionally defines a wizard logic which is partially unused yet.
This commit is contained in:
52
lib/outlook/internal_tree/html.ex
Normal file
52
lib/outlook/internal_tree/html.ex
Normal file
@ -0,0 +1,52 @@
|
||||
defmodule Outlook.InternalTree.Html do
|
||||
|
||||
alias Outlook.InternalTree.InternalNode
|
||||
alias Outlook.InternalTree.TranslationUnit
|
||||
|
||||
def to_html([ %InternalNode{type: :element} = node | rest]) do
|
||||
attr_string = Map.put(node.attributes, :uuid, node.uuid)
|
||||
|> Enum.map_join(" ", fn {k,v} -> "#{k}=\"#{v}\"" end)
|
||||
"<#{node.name} #{attr_string}>" <>
|
||||
to_html(node.content) <>
|
||||
"</#{node.name}>" <>
|
||||
to_html(rest)
|
||||
end
|
||||
|
||||
def to_html([ %InternalNode{type: :text} = node | rest]) do
|
||||
node.content <> to_html(rest)
|
||||
end
|
||||
|
||||
def to_html([ %InternalNode{type: :comment} = node | rest]) do
|
||||
"<!--#{node.content}-->" <> to_html(rest)
|
||||
end
|
||||
|
||||
def to_html([ %TranslationUnit{} = tunit | rest]) do
|
||||
~s(<span class="tunit" uuid="#{tunit.uuid}" tu-status="#{tunit.status}">#{tunit.content}</span>) <> to_html(rest)
|
||||
end
|
||||
|
||||
def to_html([]), do: ""
|
||||
|
||||
def to_html_preview([ %InternalNode{type: :element} = node | rest], target_id) do
|
||||
attr_string = Map.put(node.attributes, :uuid, node.uuid)
|
||||
|> Enum.map_join(" ", fn {k,v} -> "#{k}=\"#{v}\"" end)
|
||||
"<#{node.name} #{attr_string}>" <>
|
||||
to_html_preview(node.content, target_id) <>
|
||||
"</#{node.name}>" <>
|
||||
to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([ %InternalNode{type: :text} = node | rest], target_id) do
|
||||
~s(<span uuid="#{node.uuid}">#{node.content}</span>) <> to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([ %InternalNode{type: :comment} = node | rest], target_id) do
|
||||
~s(<span uuid="#{node.uuid}"><!--#{node.content}--></span>) <> to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([ %TranslationUnit{} = tunit | rest], target_id) do
|
||||
~s|<span class="tunit" uuid="#{tunit.uuid}" tu-status="#{tunit.status}" phx-click="select_current_tunit"
|
||||
phx-value-uuid="#{tunit.uuid}" phx-target="#{target_id}">#{tunit.content}</span>| <> to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([], _target_id), do: ""
|
||||
end
|
||||
Reference in New Issue
Block a user