This module contains types related to the nodes in an editor.
An editor consists of two types of nodes, block and inline. Block nodes are used to represent hierarchical structures like blockquotes, tables and nested lists. Inline nodes are used to represent flat structures, like text, inline images, and hard breaks.
A Block
represents a block element in your document. A block can either
have other block nodes as children, have all inline leaf nodes as children (e.g a text block),
or be a leaf node.
block : RichText.Model.Element.Element -> Children -> Block
Creates a block node. The arguments are as follows
element
is the element this block node representschildNodes
are the children related to this block node.block
(Element.element paragraph [])
(inlineChildren <| Array.fromList [ plainText "some text" ])
element : Block -> RichText.Model.Element.Element
the element from a block node
childNodes : Block -> Children
the childNodes from a block node.
withElement : RichText.Model.Element.Element -> Block -> Block
a block node with the given element set
withChildNodes : Children -> Block -> Block
a block node with the given children set
Children represents what children an editor block node can have. A block node may have other block nodes as children, inline leaf nodes as children, or it may be a leaf itself.
BlockChildren
are child nodes that are all blocks.
blockChildren : Array Block -> Children
Creates children from a block array
blockChildren (Array.fromList [ paragraphNode ])
toBlockArray : BlockChildren -> Array Block
Returns a block array from block children
InlineChildren
are child nodes that are all inline. Internally, it's represented as both
a flat structure (which can be accessed via inlineArray
), and a hierarchical structure
(which can be accessed via inlineTree
).
inlineChildren : Array Inline -> Children
Creates children derived from an inline array.
toInlineArray : InlineChildren -> Array Inline
an array of inline nodes (flat structure)
toInlineTree : InlineChildren -> Array InlineTree
a tree of mark nodes with inline leaf indices
reverseLookup : InlineChildren -> Array Path
a lookup array that maps the index of the inline array to its path in the inline tree
marksToMarkNodeList : List (List RichText.Model.Mark.Mark) -> Array InlineTree
Transforms a list of list of marks to an array of inline tree nodes
An inline leaf node represents an inline element in your document. It can either be an inline leaf node, like an image or line break, or a text node.
An inline tree is the nested structure of an inline array. Because marks when rendered can span multiple inline nodes, inline content is still technically hierarchical. When rendering or parsing, it can be useful to see this information as a tree instead of an array.
MarkNode
node that represents a mark and its inline childrenLeafNode
the index of the inline in the inline arrayinlineElement : RichText.Model.Element.Element -> List RichText.Model.Mark.Mark -> Inline
Creates an Inline
from an Element
and Mark
marks : Inline -> List RichText.Model.Mark.Mark
Derives the marks from an inline node
plainText : String -> Inline
A Inline that represents plain text
markedText : String -> List RichText.Model.Mark.Mark -> Inline
Creates an inline that represents some text with marks
List Basics.Int
A node path is a list of indexes that represent the path from a node to a child. It's the main type used to identify where a node is in the editor.
parent : Path -> Path
Returns the parent path of the given path
parent [0, 1, 2]
--> [0, 1]
increment : Path -> Path
Increments the last index in a node path if one exists.
increment [0, 1]
--> [0, 2]
decrement : Path -> Path
Decrements the last index in a node path if one exists.
decrement [0, 0]
--> [0, 0]
toString : Path -> String
String representation of a path.
toString [0, 0]
--> "0:0"
commonAncestor : Path -> Path -> Path
Returns the common ancestor of the two paths.
commonAncestor [0, 1, 2] [0, 1, 4]
--> [0, 1]