Add stripping HTML attributes
This commit is contained in:
@ -3,6 +3,25 @@ defmodule Outlook.InternalTree.Html do
|
||||
alias Outlook.InternalTree.InternalNode
|
||||
alias Outlook.InternalTree.TranslationUnit
|
||||
|
||||
@desirable_atts %{"a" => [:href], "img" => [:src]}
|
||||
|
||||
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)
|
||||
[ %{node |
|
||||
attributes: atts,
|
||||
content: strip_attributes(node.content)
|
||||
}
|
||||
| strip_attributes(rest) ]
|
||||
end
|
||||
|
||||
def strip_attributes([node | rest]) do
|
||||
[ node | strip_attributes(rest)]
|
||||
end
|
||||
|
||||
def strip_attributes([]), do: []
|
||||
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user