Yex.TextPrelim (y_ex v0.7.3)

View Source

A preliminary text representation used for initializing text content. This module provides functionality for creating text content with formatting before it is inserted into a shared document.

Use Cases

  • Creating formatted text content before inserting into a document
  • Serializing text content for transfer between documents
  • Initializing text content with specific formatting attributes

Examples

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "key", Yex.TextPrelim.from("Hello World"))
iex> {:ok, %Yex.Text{} = text} = Yex.Map.fetch(map, "key")
iex> Yex.Text.to_delta(text)
[%{insert: "Hello World"}]

Summary

Functions

Creates a new TextPrelim from either a binary string or a delta format.

Types

t()

@type t() :: %Yex.TextPrelim{delta: Yex.Text.delta()}

Functions

from(text)

@spec from(binary()) :: t()
@spec from(Yex.Text.delta()) :: t()

Creates a new TextPrelim from either a binary string or a delta format.

Examples with a binary string

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "key", Yex.TextPrelim.from("Hello World"))
iex> {:ok, %Yex.Text{} = text} = Yex.Map.fetch(map, "key")
iex> Yex.Text.to_delta(text)
[%{insert: "Hello World"}]

Examples with formatted delta

iex> doc = Yex.Doc.new()
iex> map = Yex.Doc.get_map(doc, "map")
iex> Yex.Map.set(map, "key", Yex.TextPrelim.from([%{insert: "Hello"},%{insert: " World", attributes: %{ "bold" => true }},]))
iex> {:ok, %Yex.Text{} = text} = Yex.Map.fetch(map, "key")
iex> Yex.Text.to_delta(text)
[%{insert: "Hello"}, %{attributes: %{"bold" => true}, insert: " World"}]

Parameters

  • text - Either a binary string or a delta format array