A fragment represents a node's collection of child nodes.
Like nodes, fragments are persistent data structures, and you should not mutate them or their content. Rather, you create new instances whenever needed. The API tries to make this easy.
Summary
Functions
Add a node to the end of the fragment, joining it with the last child if possible.
Add a node to the start of the fragment, joining it with the first child if possible.
Concatenate two fragments, joining adjacent text nodes with the same markup if possible.
Get the child node at the given index. Raise an error when the index is out of range.
The number of child nodes in this fragment.
Cut out the sub-fragment between the two given positions.
Cut by child index rather than position.
An empty fragment. Singleton.
Test whether this fragment is equal to another fragment.
Find the first position from the end at which the content of two fragments diverges.
Find the first position at which the content of two fragments diverges.
Find the index and inner offset corresponding to a given document position. Returns {index, offset}.
Get the first child of this fragment, or nil.
Like nodes_between/6 but threads an accumulator through each callback.
Call the given function for each child node, passing the node, its offset, and its index.
Create a fragment from something that can be interpreted as a set of nodes. For nil, it returns the empty fragment. For a fragment, the fragment itself is returned. For a node or array of nodes, a fragment containing those nodes is returned.
Create a fragment from an array of nodes, joining adjacent text nodes with the same markup.
Deserialize a fragment from its JSON representation.
Get the last child of this fragment, or nil.
Get the child node at the given index, if it exists.
Create a new fragment with the given content and size.
Call f for every descendant node between the given positions.
Create a new fragment in which the node at the given index is replaced by the given node.
Extract the text between from and to. When block_separator is given,
it will be inserted between textblocks. When leaf_text is given, it will
be used to represent non-text leaf nodes (string or function).
Serialize the content of this fragment to JSON. Returns nil if empty.
Join child debug strings with ", ".
Types
@type t() :: %ProsemirrorEx.Model.Fragment{ content: [ProsemirrorEx.Model.Node.t()], size: non_neg_integer() }
Functions
Add a node to the end of the fragment, joining it with the last child if possible.
Add a node to the start of the fragment, joining it with the first child if possible.
Concatenate two fragments, joining adjacent text nodes with the same markup if possible.
Get the child node at the given index. Raise an error when the index is out of range.
The number of child nodes in this fragment.
Cut out the sub-fragment between the two given positions.
Positions are document positions (not child indices). For text nodes, positions map to character offsets. For non-text non-leaf nodes, positions are adjusted by -1 to account for the opening token.
Cut by child index rather than position.
An empty fragment. Singleton.
Test whether this fragment is equal to another fragment.
Find the first position from the end at which the content of two fragments diverges.
Find the first position at which the content of two fragments diverges.
Find the index and inner offset corresponding to a given document position. Returns {index, offset}.
Get the first child of this fragment, or nil.
Like nodes_between/6 but threads an accumulator through each callback.
f receives (node, start_pos, parent, index, acc) and returns either:
acc— descend into children with updated accumulator{:skip, acc}— skip children, continue with updated accumulator
Call the given function for each child node, passing the node, its offset, and its index.
Create a fragment from something that can be interpreted as a set of nodes. For nil, it returns the empty fragment. For a fragment, the fragment itself is returned. For a node or array of nodes, a fragment containing those nodes is returned.
Create a fragment from an array of nodes, joining adjacent text nodes with the same markup.
Deserialize a fragment from its JSON representation.
Takes a schema and either nil (returns empty fragment) or a list of node JSON maps.
Get the last child of this fragment, or nil.
Get the child node at the given index, if it exists.
Create a new fragment with the given content and size.
Call f for every descendant node between the given positions.
f receives (node, start_pos, parent, index). When f returns false,
descending into that node is skipped.
Create a new fragment in which the node at the given index is replaced by the given node.
Extract the text between from and to. When block_separator is given,
it will be inserted between textblocks. When leaf_text is given, it will
be used to represent non-text leaf nodes (string or function).
Serialize the content of this fragment to JSON. Returns nil if empty.
Join child debug strings with ", ".