Add :eph field to %TranslationUnit{} and remove :sibling_with

Using :eph from now on to store ephemeral data like :sibling_with. Additionally
added cleaning up :eph before saving to db. And renamed InternalTree.Basic
to InternalTree.RawInternalBasic to make clear that it contains function
for an intermediary tree structure.
This commit is contained in:
Thelonius Kort
2022-12-29 22:09:26 +01:00
parent fba40236d7
commit b48274eaef
7 changed files with 100 additions and 68 deletions

View File

@ -48,7 +48,7 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
def set_sibling_with([ %{type: :element} = node | rest ]) do
[ %InternalNode{ node |
sibling_with: node.name in @block_elements && :block || :inline,
eph: %{sibling_with: node.name in @block_elements && :block || :inline},
content: set_sibling_with(node.content)
} | set_sibling_with(rest) ]
end
@ -58,11 +58,12 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
:text -> Regex.match?(~r/^\s*$/, node.content) && :both || :inline
:comment -> :both
end
[ %InternalNode{ node | sibling_with: sib_with } | set_sibling_with(rest) ]
[ %InternalNode{ node | eph: %{sibling_with: sib_with} } | set_sibling_with(rest) ]
end
def set_sibling_with([ ]), do: ( [ ] )
def strip_whitespace_textnodes [ %{type: :text} = node | rest] do
if Regex.match?(~r/^\s*$/, node.content) do
strip_whitespace_textnodes(rest)
@ -71,7 +72,6 @@ defmodule Outlook.HtmlPreparations.HtmlPreparation do
end
end
def strip_whitespace_textnodes [ %{type: :element} = node | rest] do
[ %InternalNode{ node | content: strip_whitespace_textnodes(node.content) }
| strip_whitespace_textnodes(rest) ]