Yex.XmlText (y_ex v0.8.0)

View Source

A shared type that represents an XML text node. Extends Y.Text to provide functionality for manipulating text content within XML nodes, including text formatting and navigation.

Summary

Functions

Applies a delta of changes to the text content. Returns :ok on success, :error on failure.

Converts the XML text node to a preliminary representation. This is useful when you need to serialize or transfer the text node's content and formatting.

Deletes text content starting at the specified index. Supports negative indices for deletion from the end. Returns :ok on success, :error on failure.

Applies formatting attributes to a range of text. Returns :ok on success, :error on failure.

Inserts text content at the specified index. Returns :ok on success, :error on failure.

Inserts text content with attributes at the specified index. Returns :ok on success, :error on failure.

Returns the length of the text content.

Returns the next sibling node of this text node. Returns nil if this is the last child of its parent.

Returns the parent node of this text node. Returns nil if this is a top-level XML node.

Returns the previous sibling node of this text node. Returns nil if this is the first child of its parent.

Returns the text content as a delta format, including any formatting attributes.

Returns the text content as a string, including any formatting tags.

Types

delta()

@type delta() :: Yex.Text.delta()

t()

@type t() :: %Yex.XmlText{doc: Yex.Doc.t(), reference: reference()}

Functions

apply_delta(xml_text, delta)

@spec apply_delta(t(), delta()) :: :ok | :error

Applies a delta of changes to the text content. Returns :ok on success, :error on failure.

as_prelim(xml_text)

@spec as_prelim(t()) :: Yex.XmlTextPrelim.t()

Converts the XML text node to a preliminary representation. This is useful when you need to serialize or transfer the text node's content and formatting.

delete(xml_text, index, length)

@spec delete(t(), integer(), integer()) :: :ok | :error

Deletes text content starting at the specified index. Supports negative indices for deletion from the end. Returns :ok on success, :error on failure.

format(xml_text, index, length, attr)

@spec format(t(), integer(), integer(), map()) :: :ok | :error

Applies formatting attributes to a range of text. Returns :ok on success, :error on failure.

insert(xml_text, index, content)

@spec insert(t(), integer(), Yex.input_type()) :: :ok | :error

Inserts text content at the specified index. Returns :ok on success, :error on failure.

insert(xml_text, index, content, attr)

@spec insert(t(), integer(), Yex.input_type(), map()) :: :ok | :error

Inserts text content with attributes at the specified index. Returns :ok on success, :error on failure.

length(xml_text)

@spec length(t()) :: integer()

Returns the length of the text content.

next_sibling(xml_text)

@spec next_sibling(t()) :: Yex.XmlElement.t() | t() | nil

Returns the next sibling node of this text node. Returns nil if this is the last child of its parent.

parent(xml_text)

@spec parent(t()) :: Yex.XmlElement.t() | Yex.XmlFragment.t() | nil

Returns the parent node of this text node. Returns nil if this is a top-level XML node.

prev_sibling(xml_text)

@spec prev_sibling(t()) :: Yex.XmlElement.t() | t() | nil

Returns the previous sibling node of this text node. Returns nil if this is the first child of its parent.

to_delta(xml_text)

Returns the text content as a delta format, including any formatting attributes.

to_string(xml_text)

@spec to_string(t()) :: binary()

Returns the text content as a string, including any formatting tags.