From 13c08918cce354ff6a7de4012666461de58596ca Mon Sep 17 00:00:00 2001 From: Thelonius Kort Date: Fri, 27 Jan 2023 11:30:56 +0100 Subject: [PATCH] Add treating as block and allow in both contexts --- lib/outlook/html_preparations/html_preparation.ex | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/outlook/html_preparations/html_preparation.ex b/lib/outlook/html_preparations/html_preparation.ex index 1536ba1..66c76be 100644 --- a/lib/outlook/html_preparations/html_preparation.ex +++ b/lib/outlook/html_preparations/html_preparation.ex @@ -3,8 +3,9 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do 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"] - # @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"] + # treating img as block element because inline images are not desirable + @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 atts_to_keep = ~w(href src) @@ -46,6 +47,13 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do def floki_to_internal([]), do: [] + def set_sibling_with([ node | rest ]) when node.name == "a" do + [ %InternalNode{ node | + eph: %{sibling_with: :both}, # may occur at block level (e.g. when enclosing an ) + content: set_sibling_with(node.content) + } | set_sibling_with(rest) ] + end + def set_sibling_with([ %{type: :element} = node | rest ]) do [ %InternalNode{ node | eph: %{sibling_with: node.name in @block_elements && :block || :inline},