Normalization operations for text nodes.
Normalizes content by:
- Removing empty text nodes
- Merging adjacent text nodes with identical marks
Summary
Functions
Check if a text node is empty.
Merge adjacent text nodes with identical marks.
Check if two text nodes can be merged (same marks).
Normalize a list of text nodes.
Normalize a paragraph or heading node.
Remove empty text nodes from a list.
Types
Functions
Check if a text node is empty.
Examples
iex> Quillon.Transform.Normalize.empty_text?({:text, %{text: "", marks: []}, []})
true
iex> Quillon.Transform.Normalize.empty_text?({:text, %{text: "Hi", marks: []}, []})
false
Merge adjacent text nodes with identical marks.
Uses loose equality (compares marks only, ignores text content).
Examples
iex> children = [
...> {:text, %{text: "A", marks: []}, []},
...> {:text, %{text: "B", marks: []}, []},
...> {:text, %{text: "C", marks: []}, []}
...> ]
iex> Quillon.Transform.Normalize.merge_adjacent(children)
[{:text, %{text: "ABC", marks: []}, []}]
iex> children = [
...> {:text, %{text: "Hello", marks: [:bold]}, []},
...> {:text, %{text: " world", marks: []}, []}
...> ]
iex> Quillon.Transform.Normalize.merge_adjacent(children)
[
{:text, %{text: "Hello", marks: [:bold]}, []},
{:text, %{text: " world", marks: []}, []}
]
Check if two text nodes can be merged (same marks).
Examples
iex> n1 = {:text, %{text: "Hello", marks: [:bold, :italic]}, []}
iex> n2 = {:text, %{text: " world", marks: [:italic, :bold]}, []}
iex> Quillon.Transform.Normalize.mergeable?(n1, n2)
true
iex> n1 = {:text, %{text: "Hello", marks: [:bold]}, []}
iex> n2 = {:text, %{text: " world", marks: []}, []}
iex> Quillon.Transform.Normalize.mergeable?(n1, n2)
false
Normalize a list of text nodes.
Removes empty text nodes and merges adjacent nodes with identical marks.
Examples
iex> children = [
...> {:text, %{text: "Hello", marks: [:bold]}, []},
...> {:text, %{text: " world", marks: [:bold]}, []},
...> {:text, %{text: "", marks: []}, []}
...> ]
iex> Quillon.Transform.Normalize.normalize(children)
[{:text, %{text: "Hello world", marks: [:bold]}, []}]
iex> Quillon.Transform.Normalize.normalize([])
[]
Normalize a paragraph or heading node.
Examples
iex> para = {:paragraph, %{}, [
...> {:text, %{text: "Hello", marks: [:bold]}, []},
...> {:text, %{text: " world", marks: [:bold]}, []}
...> ]}
iex> Quillon.Transform.Normalize.normalize_block(para)
{:paragraph, %{}, [{:text, %{text: "Hello world", marks: [:bold]}, []}]}
Remove empty text nodes from a list.
Examples
iex> children = [
...> {:text, %{text: "Hello", marks: []}, []},
...> {:text, %{text: "", marks: []}, []},
...> {:text, %{text: "world", marks: []}, []}
...> ]
iex> Quillon.Transform.Normalize.remove_empty(children)
[
{:text, %{text: "Hello", marks: []}, []},
{:text, %{text: "world", marks: []}, []}
]