Utilities for working with Quillon marks.
Marks apply formatting to text nodes. They come in two forms:
- Simple marks: atoms like
:bold,:italic - Attributed marks: tuples like
{:link, %{href: "..."}}
Summary
Functions
Add a mark to a marks list if not already present.
Check if a mark is an attributed (tuple) mark.
Get a mark of a given type from a marks list. Returns nil if not found.
Check if a marks list contains a mark of a given type.
Check if a value is a valid mark (simple or attributed).
Get the attrs of a mark. Returns empty map for simple marks.
Get the type of a mark.
Compare two marks lists for equality, ignoring order.
Remove a mark of a given type from a marks list.
Check if a mark is a simple (atom) mark.
Toggle a mark in a marks list (add if absent, remove if present).
Functions
Add a mark to a marks list if not already present.
Examples
iex> Quillon.Mark.add_mark([:bold], :italic)
[:bold, :italic]
iex> Quillon.Mark.add_mark([:bold], :bold)
[:bold]
iex> Quillon.Mark.add_mark([], {:link, %{href: "/"}})
[{:link, %{href: "/"}}]
Check if a mark is an attributed (tuple) mark.
Examples
iex> Quillon.Mark.attributed?({:link, %{href: "/page"}})
true
iex> Quillon.Mark.attributed?(:bold)
false
iex> Quillon.Mark.attributed?({:unknown, %{}})
false
Get a mark of a given type from a marks list. Returns nil if not found.
Examples
iex> Quillon.Mark.get_mark([:bold, :italic], :bold)
:bold
iex> Quillon.Mark.get_mark([{:link, %{href: "/page"}}], :link)
{:link, %{href: "/page"}}
iex> Quillon.Mark.get_mark([:bold], :link)
nil
Check if a marks list contains a mark of a given type.
Examples
iex> Quillon.Mark.has_mark?([:bold, :italic], :bold)
true
iex> Quillon.Mark.has_mark?([:bold], :italic)
false
iex> Quillon.Mark.has_mark?([{:link, %{href: "/"}}], :link)
true
iex> Quillon.Mark.has_mark?([], :bold)
false
Check if a value is a valid mark (simple or attributed).
Examples
iex> Quillon.Mark.mark?(:bold)
true
iex> Quillon.Mark.mark?({:link, %{href: "/"}})
true
iex> Quillon.Mark.mark?("bold")
false
iex> Quillon.Mark.mark?({:unknown, %{}})
false
Get the attrs of a mark. Returns empty map for simple marks.
Examples
iex> Quillon.Mark.mark_attrs(:bold)
%{}
iex> Quillon.Mark.mark_attrs({:link, %{href: "/page", title: "Link"}})
%{href: "/page", title: "Link"}
Get the type of a mark.
Examples
iex> Quillon.Mark.mark_type(:bold)
:bold
iex> Quillon.Mark.mark_type({:link, %{href: "/page"}})
:link
Compare two marks lists for equality, ignoring order.
Examples
iex> Quillon.Mark.marks_equal?([:bold, :italic], [:italic, :bold])
true
iex> Quillon.Mark.marks_equal?([:bold], [:bold, :italic])
false
iex> Quillon.Mark.marks_equal?([], [])
true
Remove a mark of a given type from a marks list.
Examples
iex> Quillon.Mark.remove_mark([:bold, :italic], :bold)
[:italic]
iex> Quillon.Mark.remove_mark([{:link, %{href: "/"}}], :link)
[]
iex> Quillon.Mark.remove_mark([:bold], :italic)
[:bold]
Check if a mark is a simple (atom) mark.
Examples
iex> Quillon.Mark.simple?(:bold)
true
iex> Quillon.Mark.simple?(:italic)
true
iex> Quillon.Mark.simple?({:link, %{href: "/"}})
false
iex> Quillon.Mark.simple?(:unknown)
false
Toggle a mark in a marks list (add if absent, remove if present).
Examples
iex> Quillon.Mark.toggle_mark([:bold], :italic)
[:bold, :italic]
iex> Quillon.Mark.toggle_mark([:bold, :italic], :bold)
[:italic]