High-level API for common formatting operations.
Convenience wrappers around Quillon.Transform functions.
Example
para = Quillon.paragraph("Hello world")
# Toggle bold on "Hello"
para = Quillon.Commands.toggle_bold(para, 0, 5)
# Add a link
para = Quillon.Commands.set_link(para, 6, 11, "https://example.com")
# Clear all formatting
para = Quillon.Commands.clear_formatting(para, 0, 11)
Summary
Functions
Remove all formatting from the given range.
Check if the selection has a specific mark type.
Set font color on the given range.
Set a highlight on the given range.
Set a link on the given range.
Set a mention on the given range.
Toggle bold formatting on the given range.
Toggle code formatting on the given range.
Toggle italic formatting on the given range.
Toggle strikethrough formatting on the given range.
Toggle subscript formatting on the given range.
Toggle superscript formatting on the given range.
Toggle underline formatting on the given range.
Remove font color from the given range.
Remove highlight from the given range.
Remove link from the given range.
Remove mention from the given range.
Types
Functions
@spec clear_formatting(block(), non_neg_integer(), non_neg_integer()) :: block()
Remove all formatting from the given range.
Removes all simple marks (bold, italic, underline, strike, code) and attributed marks (link) from the text in the range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: [:bold, :italic]}, []}]}
iex> Quillon.Commands.clear_formatting(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
@spec selection_has_mark?(block(), non_neg_integer(), non_neg_integer(), atom()) :: boolean()
Check if the selection has a specific mark type.
Returns true only if ALL text in the range has the mark.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: [:bold]}, []}]}
iex> Quillon.Commands.selection_has_mark?(para, 0, 5, :bold)
true
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Commands.selection_has_mark?(para, 0, 5, :bold)
false
@spec set_font_color(block(), non_neg_integer(), non_neg_integer(), String.t()) :: block()
Set font color on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "red text", marks: []}, []}]}
iex> Quillon.Commands.set_font_color(para, 0, 8, "#ff0000")
{:paragraph, %{}, [{:text, %{text: "red text", marks: [{:font_color, %{color: "#ff0000"}}]}, []}]}
@spec set_highlight(block(), non_neg_integer(), non_neg_integer(), String.t()) :: block()
Set a highlight on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "important", marks: []}, []}]}
iex> Quillon.Commands.set_highlight(para, 0, 9, "yellow")
{:paragraph, %{}, [{:text, %{text: "important", marks: [{:highlight, %{color: "yellow"}}]}, []}]}
@spec set_link(block(), non_neg_integer(), non_neg_integer(), String.t() | map()) :: block()
Set a link on the given range.
Accepts either a URL string or a map of link attributes.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "click here", marks: []}, []}]}
iex> Quillon.Commands.set_link(para, 0, 10, "https://example.com")
{:paragraph, %{}, [{:text, %{text: "click here", marks: [{:link, %{href: "https://example.com"}}]}, []}]}
iex> para = {:paragraph, %{}, [{:text, %{text: "click here", marks: []}, []}]}
iex> Quillon.Commands.set_link(para, 0, 10, %{href: "/page", title: "Link"})
{:paragraph, %{}, [{:text, %{text: "click here", marks: [{:link, %{href: "/page", title: "Link"}}]}, []}]}
@spec set_mention(block(), non_neg_integer(), non_neg_integer(), map()) :: block()
Set a mention on the given range.
Accepts a map with :id, :type, and :label attributes.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "@alice", marks: []}, []}]}
iex> Quillon.Commands.set_mention(para, 0, 6, %{id: "user_123", type: "user", label: "@alice"})
{:paragraph, %{}, [{:text, %{text: "@alice", marks: [{:mention, %{id: "user_123", type: "user", label: "@alice"}}]}, []}]}
@spec toggle_bold(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle bold formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Commands.toggle_bold(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "Hello", marks: [:bold]}, []}]}
@spec toggle_code(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle code formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Commands.toggle_code(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "Hello", marks: [:code]}, []}]}
@spec toggle_italic(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle italic formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Commands.toggle_italic(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "Hello", marks: [:italic]}, []}]}
@spec toggle_strike(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle strikethrough formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Commands.toggle_strike(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "Hello", marks: [:strike]}, []}]}
@spec toggle_subscript(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle subscript formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "H2O", marks: []}, []}]}
iex> Quillon.Commands.toggle_subscript(para, 1, 2)
{:paragraph, %{}, [{:text, %{text: "H", marks: []}, []}, {:text, %{text: "2", marks: [:subscript]}, []}, {:text, %{text: "O", marks: []}, []}]}
@spec toggle_superscript(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle superscript formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "x2", marks: []}, []}]}
iex> Quillon.Commands.toggle_superscript(para, 1, 2)
{:paragraph, %{}, [{:text, %{text: "x", marks: []}, []}, {:text, %{text: "2", marks: [:superscript]}, []}]}
@spec toggle_underline(block(), non_neg_integer(), non_neg_integer()) :: block()
Toggle underline formatting on the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Commands.toggle_underline(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "Hello", marks: [:underline]}, []}]}
@spec unset_font_color(block(), non_neg_integer(), non_neg_integer()) :: block()
Remove font color from the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "text", marks: [{:font_color, %{color: "#ff0000"}}]}, []}]}
iex> Quillon.Commands.unset_font_color(para, 0, 4)
{:paragraph, %{}, [{:text, %{text: "text", marks: []}, []}]}
@spec unset_highlight(block(), non_neg_integer(), non_neg_integer()) :: block()
Remove highlight from the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "text", marks: [{:highlight, %{color: "yellow"}}]}, []}]}
iex> Quillon.Commands.unset_highlight(para, 0, 4)
{:paragraph, %{}, [{:text, %{text: "text", marks: []}, []}]}
@spec unset_link(block(), non_neg_integer(), non_neg_integer()) :: block()
Remove link from the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "click", marks: [{:link, %{href: "/"}}]}, []}]}
iex> Quillon.Commands.unset_link(para, 0, 5)
{:paragraph, %{}, [{:text, %{text: "click", marks: []}, []}]}
@spec unset_mention(block(), non_neg_integer(), non_neg_integer()) :: block()
Remove mention from the given range.
Examples
iex> para = {:paragraph, %{}, [{:text, %{text: "@alice", marks: [{:mention, %{id: "1", type: "user", label: "@alice"}}]}, []}]}
iex> Quillon.Commands.unset_mention(para, 0, 6)
{:paragraph, %{}, [{:text, %{text: "@alice", marks: []}, []}]}