Add support for img tags
This commit is contained in:
@ -5,6 +5,8 @@ defmodule Outlook.InternalTree.Html do
|
||||
|
||||
@desirable_atts %{"a" => [:href], "img" => [:src]}
|
||||
|
||||
@void_elements ~w(img br hr)
|
||||
|
||||
def strip_attributes([%InternalNode{type: :element} = node | rest]) do
|
||||
d_atts = Map.get(@desirable_atts, node.name, [])
|
||||
atts = Map.reject(node.attributes, fn {k,_} -> k not in d_atts end)
|
||||
@ -22,6 +24,11 @@ defmodule Outlook.InternalTree.Html do
|
||||
def strip_attributes([]), do: []
|
||||
|
||||
|
||||
def to_html([%{type: :element} = node | rest]) when node.name in @void_elements do
|
||||
attr_string = Enum.map_join(node.attributes, "", fn {k,v} -> " #{k}=\"#{v}\"" end)
|
||||
"<#{node.name}#{attr_string}>" <> to_html(rest)
|
||||
end
|
||||
|
||||
def to_html([%{type: :element} = node | rest]) do
|
||||
attr_string = Enum.map_join(node.attributes, "", fn {k,v} -> " #{k}=\"#{v}\"" end)
|
||||
"<#{node.name}#{attr_string}>" <>
|
||||
|
||||
Reference in New Issue
Block a user