Add treating <img> as block and allow <a> in both contexts
This commit is contained in:
@ -3,8 +3,9 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
|
|||||||
|
|
||||||
alias Outlook.InternalTree.InternalNode
|
alias Outlook.InternalTree.InternalNode
|
||||||
|
|
||||||
@block_elements ["address","article","aside","blockquote","canvas","dd","div","dl","dt","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hr","li","main","nav","noscript","ol","p","pre","section","table","tfoot","ul","video"]
|
# treating img as block element because inline images are not desirable
|
||||||
# @inline_elements ["a","abbr","acronym","b","bdo","big","br","button","cite","code","dfn","em","i","img","input","kbd","label","map","object","output","q","samp","script","select","small","span","strong","sub","sup","textarea","time","tt","u","var"]
|
@block_elements ~w(img address article aside blockquote canvas dd div dl dt fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 header hr li main nav noscript ol p pre section table tfoot ul video)
|
||||||
|
# @inline_elements ~w(a abbr acronym b bdo big br button cite code dfn em i input kbd label map object output q samp script select small span strong sub sup textarea time tt u var)
|
||||||
|
|
||||||
defp clean_atts_to_map(atts) do
|
defp clean_atts_to_map(atts) do
|
||||||
atts_to_keep = ~w(href src)
|
atts_to_keep = ~w(href src)
|
||||||
@ -46,6 +47,13 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
|
|||||||
def floki_to_internal([]), do: []
|
def floki_to_internal([]), do: []
|
||||||
|
|
||||||
|
|
||||||
|
def set_sibling_with([ node | rest ]) when node.name == "a" do
|
||||||
|
[ %InternalNode{ node |
|
||||||
|
eph: %{sibling_with: :both}, # <a> may occur at block level (e.g. when enclosing an <img>)
|
||||||
|
content: set_sibling_with(node.content)
|
||||||
|
} | set_sibling_with(rest) ]
|
||||||
|
end
|
||||||
|
|
||||||
def set_sibling_with([ %{type: :element} = node | rest ]) do
|
def set_sibling_with([ %{type: :element} = node | rest ]) do
|
||||||
[ %InternalNode{ node |
|
[ %InternalNode{ node |
|
||||||
eph: %{sibling_with: node.name in @block_elements && :block || :inline},
|
eph: %{sibling_with: node.name in @block_elements && :block || :inline},
|
||||||
|
|||||||
Reference in New Issue
Block a user