Update to_html/1 to accept maps instead of only %InternalNode{}s
This commit is contained in:
@ -22,24 +22,23 @@ defmodule Outlook.InternalTree.Html do
|
|||||||
def strip_attributes([]), do: []
|
def strip_attributes([]), do: []
|
||||||
|
|
||||||
|
|
||||||
def to_html([ %InternalNode{type: :element} = node | rest]) do
|
def to_html([%{type: :element} = node | rest]) do
|
||||||
attr_string = Map.put(node.attributes, :uuid, node.uuid)
|
attr_string = Enum.map_join(node.attributes, "", fn {k,v} -> " #{k}=\"#{v}\"" end)
|
||||||
|> Enum.map_join(" ", fn {k,v} -> "#{k}=\"#{v}\"" end)
|
"<#{node.name}#{attr_string}>" <>
|
||||||
"<#{node.name} #{attr_string}>" <>
|
|
||||||
to_html(node.content) <>
|
to_html(node.content) <>
|
||||||
"</#{node.name}>" <>
|
"</#{node.name}>" <>
|
||||||
to_html(rest)
|
to_html(rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_html([ %InternalNode{type: :text} = node | rest]) do
|
def to_html([%{type: :text} = node | rest]) do
|
||||||
node.content <> to_html(rest)
|
node.content <> to_html(rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_html([ %InternalNode{type: :comment} = node | rest]) do
|
def to_html([%{type: :comment} = node | rest]) do
|
||||||
"<!--#{node.content}-->" <> to_html(rest)
|
"<!--#{node.content}-->" <> to_html(rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_html([ %TranslationUnit{} = tunit | rest]) do
|
def to_html([%TranslationUnit{} = tunit | rest]) do
|
||||||
~s(<span class="tunit" uuid="#{tunit.uuid}" tu-status="#{tunit.status}">#{tunit.content}</span>) <> to_html(rest)
|
~s(<span class="tunit" uuid="#{tunit.uuid}" tu-status="#{tunit.status}">#{tunit.content}</span>) <> to_html(rest)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user