Documentation ¶
Overview ¶
Package model implements ProseMirror's document model, along with the mechanisms needed to support schemas.
Index ¶
- Variables
- func SameMarkSet(a, b []*Mark) bool
- type Attribute
- type AttributeSpec
- type ContentMatch
- type DiffEnd
- type Fragment
- func (f *Fragment) Append(other *Fragment) *Fragment
- func (f *Fragment) Child(index int) (*Node, error)
- func (f *Fragment) ChildCount() int
- func (f *Fragment) Cut(from int, to ...int) *Fragment
- func (f *Fragment) Eq(other *Fragment) bool
- func (f *Fragment) FindDiffEnd(other *Fragment, pos ...int) *DiffEnd
- func (f *Fragment) FindDiffStart(other *Fragment, pos ...int) *int
- func (f *Fragment) FirstChild() *Node
- func (f *Fragment) ForEach(fn func(node *Node, offset, index int))
- func (f *Fragment) LastChild() *Node
- func (f *Fragment) MaybeChild(index int) *Node
- func (f *Fragment) NodesBetween(from, to int, fn NBCallback, nodeStart int, parent *Node) *int
- func (f *Fragment) ReplaceChild(index int, node *Node) *Fragment
- func (f *Fragment) String() string
- func (f *Fragment) ToJSON() interface{}
- type Mark
- type MarkSpec
- type MarkType
- type NBCallback
- type Node
- func (n *Node) CanReplace(from, to int, args ...interface{}) bool
- func (n *Node) Child(index int) (*Node, error)
- func (n *Node) ChildCount() int
- func (n *Node) ContentMatchAt(index int) (*ContentMatch, error)
- func (n *Node) Copy(content ...*Fragment) *Node
- func (n *Node) Cut(from int, to ...int) *Node
- func (n *Node) Eq(other *Node) bool
- func (n *Node) FirstChild() *Node
- func (n *Node) ForEach(fn func(node *Node, offset, index int))
- func (n *Node) HasMarkup(typ *NodeType, args ...interface{}) bool
- func (n *Node) IsAtom() bool
- func (n *Node) IsBlock() bool
- func (n *Node) IsInline() bool
- func (n *Node) IsLeaf() bool
- func (n *Node) IsText() bool
- func (n *Node) LastChild() *Node
- func (n *Node) Mark(marks []*Mark) *Node
- func (n *Node) MaybeChild(index int) *Node
- func (n *Node) NodeAt(pos int) *Node
- func (n *Node) NodeSize() int
- func (n *Node) NodesBetween(from, to int, fn NBCallback, startPos ...int)
- func (n *Node) Replace(from, to int, slice *Slice) (*Node, error)
- func (n *Node) Resolve(pos int) (*ResolvedPos, error)
- func (n *Node) SameMarkup(other *Node) bool
- func (n *Node) Slice(from int, args ...interface{}) (*Slice, error)
- func (n *Node) String() string
- func (n *Node) TextBetween(from, to int, args ...string) string
- func (n *Node) TextContent() string
- func (n *Node) ToJSON() map[string]interface{}
- func (n *Node) UnitCodeAt(pos int) uint16
- func (n *Node) WithText(text string) *Node
- type NodeSpec
- type NodeType
- func (nt *NodeType) AllowsMarkType(markType *MarkType) bool
- func (nt *NodeType) AllowsMarks(marks []*Mark) bool
- func (nt *NodeType) Create(attrs map[string]interface{}, content interface{}, marks []*Mark) (*Node, error)
- func (nt *NodeType) CreateAndFill(args ...interface{}) (*Node, error)
- func (nt *NodeType) CreateChecked(args ...interface{}) (*Node, error)
- func (nt *NodeType) HasRequiredAttrs() bool
- func (nt *NodeType) IsAtom() bool
- func (nt *NodeType) IsBlock() bool
- func (nt *NodeType) IsInline() bool
- func (nt *NodeType) IsLeaf() bool
- func (nt *NodeType) IsText() bool
- func (nt *NodeType) ValidContent(content *Fragment) bool
- type ReplaceError
- type ResolvedPos
- func (r *ResolvedPos) After(depth ...int) (int, error)
- func (r *ResolvedPos) Before(depth ...int) (int, error)
- func (r *ResolvedPos) Doc() *Node
- func (r *ResolvedPos) End(depth ...int) int
- func (r *ResolvedPos) Index(depth ...int) int
- func (r *ResolvedPos) IndexAfter(depth ...int) int
- func (r *ResolvedPos) Marks() []*Mark
- func (r *ResolvedPos) Node(depth ...int) *Node
- func (r *ResolvedPos) NodeAfter() (*Node, error)
- func (r *ResolvedPos) NodeBefore() (*Node, error)
- func (r *ResolvedPos) Parent() *Node
- func (r *ResolvedPos) SharedDepth(pos int) int
- func (r *ResolvedPos) Start(depth ...int) int
- func (r *ResolvedPos) TextOffset() int
- type Schema
- func (s *Schema) Mark(typ interface{}, args ...map[string]interface{}) *Mark
- func (s *Schema) MarkFromJSON(raw []byte) (*Mark, error)
- func (s *Schema) MarkType(name string) (*MarkType, error)
- func (s *Schema) Node(typ interface{}, args ...interface{}) (*Node, error)
- func (s *Schema) NodeFromJSON(raw []byte) (*Node, error)
- func (s *Schema) NodeType(name string) (*NodeType, error)
- func (s *Schema) Text(text string, marks ...[]*Mark) *Node
- type SchemaSpec
- type Slice
Constants ¶
This section is empty.
Variables ¶
var EmptyContentMatch = NewContentMatch(true)
EmptyContentMatch is an empty ContentMatch.
var EmptyFragment = &Fragment{Content: nil, Size: 0}
EmptyFragment is an empty fragment.
var EmptySlice = NewSlice(EmptyFragment, 0, 0)
EmptySlice is an empty slice.
var NoMarks = []*Mark{}
NoMarks is the empty set of marks (none in JS)
Functions ¶
func SameMarkSet ¶
SameMarkSet tests whether two sets of marks are identical.
Types ¶
type Attribute ¶
type Attribute struct { HasDefault bool Default interface{} }
Attribute descriptors
func NewAttribute ¶
func NewAttribute(options *AttributeSpec) *Attribute
NewAttribute is the constructor for Attribute.
type AttributeSpec ¶
type AttributeSpec struct { // The default value for this attribute, to use when no explicit value is // provided. Attributes that have no default must be provided whenever a // node or mark of a type that has them is created. Default interface{} `json:"default,omitempty"` }
AttributeSpec is used to define attributes on nodes or marks.
type ContentMatch ¶
type ContentMatch struct { // True when this match state represents a valid end of the node. ValidEnd bool // contains filtered or unexported fields }
ContentMatch represents a match state of a node type's content expression, and can be used to find out whether further content matches here, and whether a given position is a valid end of the node.
func NewContentMatch ¶
func NewContentMatch(validEnd bool) *ContentMatch
NewContentMatch is the constructor for ContentMatch.
func ParseContentMatch ¶
func ParseContentMatch(str string, nodeTypes []*NodeType) (*ContentMatch, error)
ParseContentMatch builds a ContentMatch from a string expression.
func (*ContentMatch) FillBefore ¶
func (cm *ContentMatch) FillBefore(after *Fragment, toEnd ...bool) *Fragment
FillBefore tries to match the given fragment, and if that fails, see if it can be made to match by inserting nodes in front of it. When successful, return a fragment of inserted nodes (which may be empty if nothing had to be inserted). When toEnd is true, only return a fragment if the resulting match goes to the end of the content expression.
func (*ContentMatch) MatchFragment ¶
func (cm *ContentMatch) MatchFragment(frag *Fragment, args ...int) *ContentMatch
MatchFragment tries to match a fragment. Returns the resulting match when successful.
:: (Fragment, ?number, ?number) → ?ContentMatch
func (*ContentMatch) MatchType ¶
func (cm *ContentMatch) MatchType(typ *NodeType) *ContentMatch
MatchType matches a node type, returning a match after that node if successful.
type Fragment ¶
type Fragment struct { Content []*Node // Size is the total of the size of its content nodes. Size int }
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.
func FragmentFrom ¶
FragmentFrom creates a fragment from something that can be interpreted as a set of nodes. For null, it returns the empty fragment. For a fragment, the fragment itself. For a node or array of nodes, a fragment containing those nodes.
func FragmentFromArray ¶
FragmentFromArray builds a fragment from an array of nodes. Ensures that adjacent text nodes with the same marks are joined together.
func FragmentFromJSON ¶
FragmentFromJSON deserializes a fragment from its JSON representation.
func NewFragment ¶
NewFragment is the constructor for Fragment.
func (*Fragment) Append ¶
Append creates a new fragment containing the combined content of this fragment and the other.
func (*Fragment) Child ¶
Child gets the child node at the given index. Raise an error when the index is out of range.
func (*Fragment) ChildCount ¶
ChildCount returns the number of child nodes in this fragment.
func (*Fragment) FindDiffEnd ¶
FindDiffEnd finds the first position, searching from the end, at which this fragment and the given fragment differ, or `null` if they are the same. Since this position will not be the same in both nodes, an object with two separate positions is returned.
func (*Fragment) FindDiffStart ¶
FindDiffStart finds the first position at which this fragment and another fragment differ, or null if they are the same.
func (*Fragment) FirstChild ¶
FirstChild returns the first child of the fragment, or null if it is empty.
func (*Fragment) ForEach ¶ added in v0.4.0
ForEach calls fn for every child node, passing the node, its offset into this parent node, and its index.
func (*Fragment) LastChild ¶
LastChild returns the last child of the fragment, or null if it is empty.
func (*Fragment) MaybeChild ¶
MaybeChild gets the child node at the given index, if it exists.
func (*Fragment) NodesBetween ¶
NodesBetween invokes a callback for all descendant nodes between the given two positions (relative to start of this fragment). Doesn't descend into a node when the callback returns false.
func (*Fragment) ReplaceChild ¶
ReplaceChild creates a new fragment in which the node at the given index is replaced by the given node.
type Mark ¶
Mark is a piece of information that can be attached to a node, such as it being emphasized, in code font, or a link. It has a type and optionally a set of attributes that provide further information (such as the target of the link). Marks are created through a Schema, which controls which types exist and which attributes they have.
func MarkFromJSON ¶
MarkFromJSON deserializes a mark from its JSON representation.
func MarkSetFrom ¶
func MarkSetFrom(marks ...interface{}) []*Mark
MarkSetFrom creates a properly sorted mark set from null, a single mark, or an unsorted array of marks.
func (*Mark) AddToSet ¶
AddToSet , when given a set of marks, creates a new set which contains this one as well, in the right position. If this mark is already in the set, the set itself is returned. If any marks that are set to be exclusive with this mark are present, those are replaced by this one.
func (*Mark) RemoveFromSet ¶
RemoveFromSet removes this mark from the given set, returning a new set. If this mark is not in the set, the set itself is returned.
type MarkSpec ¶
type MarkSpec struct { // In JavaScript, the MarkSpec are kept in an OrderedMap. In Go, the map // doesn't preserve the order of the keys. Instead, an array is used, and // the key is kept here. Key string `json:"-"` // The attributes that marks of this type get. Attrs map[string]*AttributeSpec `json:"attrs,omitempty"` // Whether this mark should be active when the cursor is positioned // at its end (or at its start when that is also the start of the // parent node). Defaults to true. Inclusive *bool `json:"inclusive,omitempty"` // Determines which other marks this mark can coexist with. Should be a // space-separated strings naming other marks or groups of marks. When a // mark is added to a set, all marks that it excludes are removed in the // process. If the set contains any mark that excludes the new mark but is // not, itself, excluded by the new mark, the mark can not be added an the // set. You can use the value `"_"` to indicate that the mark excludes all // marks in the schema. // // Defaults to only being exclusive with marks of the same type. You can // set it to an empty string (or any string not containing the mark's own // name) to allow multiple marks of a given type to coexist (as long as // they have different attributes). Excludes *string `json:"excludes,omitempty"` // The group or space-separated groups to which this mark belongs. Group string `json:"group,omitempty"` }
MarkSpec is an object describing a mark type.
type MarkType ¶
type MarkType struct { // The name of the mark type. Name string Rank int // The schema that this mark type instance is part of. Schema *Schema // The spec on which the type is based. Spec *MarkSpec Excluded []*MarkType Attrs map[string]*Attribute Instance *Mark }
MarkType is the type object for marks. Like nodes, marks (which are associated with nodes to signify things like emphasis or being part of a link) are tagged with type objects, which are instantiated once per Schema.
func NewMarkType ¶
NewMarkType is the constructor for MarkType.
func (*MarkType) Create ¶
Create a mark of this type. attrs may be null or an object containing only some of the mark's attributes. The others, if they have defaults, will be added.
type NBCallback ¶
NBCallback is a type of the function used for NodesBetween. The arguments are: - the current node - the current position - the parent node - the index of the current node in the list of its parent children. If the callback returns false, it will prevent NodesBetween to descend into this node.
type Node ¶
type Node struct { // The type of node that this is. Type *NodeType // An object mapping attribute names to values. The kind of attributes // allowed and required are determined by the node type. Attrs map[string]interface{} // A container holding the node's children. Content *Fragment // For text nodes, this contains the node's text content. Text *string // The marks (things like whether it is emphasized or part of a link) // applied to this node. Marks []*Mark }
Node class represents a node in the tree that makes up a ProseMirror document. So a document is an instance of Node, with children that are also instances of Node.
Nodes are persistent data structures. Instead of changing them, you create new ones with the content you want. Old ones keep pointing at the old document shape. This is made cheaper by sharing structure between the old and new data as much as possible, which a tree shape like this (without back pointers) makes easy.
Do not directly mutate the properties of a Node object.
func NewTextNode ¶
NewTextNode is a constructor for text Node.
func NodeFromJSON ¶
NodeFromJSON deserializes a node from its JSON representation.
func (*Node) CanReplace ¶
CanReplace tests whether replacing the range between from and to (by child index) with the given replacement fragment (which defaults to the empty fragment) would leave the node's content valid. You can optionally pass start and end indices into the replacement fragment.
:: (number, number, ?Fragment, ?number, ?number) → bool
func (*Node) Child ¶
Child gets the child node at the given index. Raises an error when the index is out of range.
func (*Node) ChildCount ¶
ChildCount returns the number of children that the node has.
func (*Node) ContentMatchAt ¶
func (n *Node) ContentMatchAt(index int) (*ContentMatch, error)
ContentMatchAt gets the content match in this node at the given index.
func (*Node) Copy ¶
Copy creates a new node with the same markup as this node, containing the given content (or empty, if no content is given).
func (*Node) Cut ¶
Cut creates a copy of this node with only the content between the given positions. If to is not given, it defaults to the end of the node.
func (*Node) FirstChild ¶
FirstChild returns this node's first child, or null if there are no children.
func (*Node) ForEach ¶ added in v0.4.0
ForEach calls fn for every child node, passing the node, its offset into this parent node, and its index.
func (*Node) HasMarkup ¶
HasMarkup checks whether this node's markup correspond to the given type, attributes, and marks.
:: (NodeType, ?Object, ?Mark) → bool
func (*Node) IsAtom ¶ added in v0.4.12
IsAtom returns true when this is an atom, i.e. when it does not have directly editable content. This is usually the same as `isLeaf`, but can be configured with the [`atom` property](#model.NodeSpec.atom) on a node's spec (typically used when the node is displayed as an uneditable [node view](#view.NodeView)).
func (*Node) IsInline ¶
IsInline returns true when this is an inline node (a text node or a node that can appear among text).
func (*Node) LastChild ¶
LastChild returns this node's last child, or null if there are no children.
func (*Node) Mark ¶
Mark creates a copy of this node, with the given set of marks instead of the node's own marks.
func (*Node) MaybeChild ¶
MaybeChild gets the child node at the given index, if it exists.
func (*Node) NodeSize ¶
NodeSize returns the size of this node, as defined by the integer-based indexing scheme. For text nodes, this is the amount of characters. For other leaf nodes, it is one. For non-leaf nodes, it is the size of the content plus two (the start and end token).
func (*Node) NodesBetween ¶
func (n *Node) NodesBetween(from, to int, fn NBCallback, startPos ...int)
NodesBetween invokes a callback for all descendant nodes recursively between the given two positions that are relative to start of this node's content. The callback is invoked with the node, its parent-relative position, its parent node, and its child index. When the callback returns false for a given node, that node's children will not be recursed over. The last parameter can be used to specify a starting position to count from.
func (*Node) Replace ¶
Replace the part of the document between the given positions with the given slice. The slice must 'fit', meaning its open sides must be able to connect to the surrounding content, and its content nodes must be valid children for the node they are placed into. If any of this is violated, an error of type ReplaceError is thrown.
func (*Node) Resolve ¶
func (n *Node) Resolve(pos int) (*ResolvedPos, error)
Resolve the given position in the document, returning an object with information about its context.
func (*Node) SameMarkup ¶
SameMarkup compares the markup (type, attributes, and marks) of this node to those of another. Returns true if both have the same markup.
func (*Node) Slice ¶
Slice cuts out the part of the document between the given positions, and return it as a Slice object.
func (*Node) TextBetween ¶
TextBetween gets all text between positions from and to. When blockSeparator is given, it will be inserted whenever a new block node is started. When leafText is given, it'll be inserted for every non-text leaf node encountered.
func (*Node) TextContent ¶
TextContent concatenates all the text nodes found in this fragment and its children.
func (*Node) UnitCodeAt ¶ added in v0.4.5
UnitCodeAt returns the UTF-16 unit code at the given position. It is a function that does not exist in the original prosemirror in JS, as it is only useful in Go to emulate the behavior of strings in JavaScript. In Go, the strings are encoded as UTF-8 by default, but in JavaScript, they can be seen as an array of UTF-16 unit codes. In particular, it means that a single unicode character with a value > 0xffff are a surrogate pair of two UTF-16 unit codes in JavaScript.
type NodeSpec ¶
type NodeSpec struct { // In JavaScript, the NodeSpec are kept in an OrderedMap. In Go, the map // doesn't preserve the order of the keys. Instead, an array is used, and // the key is kept here. Key string `json:"-"` // The content expression for this node, as described in the schema guide. // When not given, the node does not allow any content. Content string `json:"content,omitempty"` // The marks that are allowed inside of this node. May be a space-separated // string referring to mark names or groups, "_" to explicitly allow all // marks, or "" to disallow marks. When not given, nodes with inline // content default to allowing all marks, other nodes default to not // allowing marks. Marks *string `json:"marks,omitempty"` // The group or space-separated groups to which this node belongs, which // can be referred to in the content expressions for the schema. Group string `json:"group,omitempty"` // Should be set to true for inline nodes. (Implied for text nodes.) Inline bool `json:"inline,omitempty"` // Can be set to true to indicate that, though this isn't a [leaf // node](#model.NodeType.isLeaf), it doesn't have directly editable // content and should be treated as a single unit in the view. Atom bool `json:"atom,omitempty"` // The attributes that nodes of this type get. Attrs map[string]*AttributeSpec `json:"attrs,omitempty"` // Defines the default way a node of this type should be serialized to a // string representation for debugging (e.g. in error messages). ToDebugString func(*Node) string `json:"-"` }
NodeSpec is an object describing a node type.
type NodeType ¶
type NodeType struct { // The name the node type has in this schema. Name string // A link back to the `Schema` the node type belongs to. Schema *Schema // The spec that this type is based on Spec *NodeSpec Groups []string Attrs map[string]*Attribute DefaultAttrs map[string]interface{} // The starting match of the node type's content expression. ContentMatch *ContentMatch // The set of marks allowed in this node. `null` means all marks are // allowed. MarkSet *[]*MarkType // True if this node type has inline content. InlineContent bool }
NodeType are objects allocated once per Schema and used to tag Node instances. They contain information about the node type, such as its name and what kind of node it represents.
func NewNodeType ¶
NewNodeType is the constructor for NodeType.
func (*NodeType) AllowsMarkType ¶
AllowsMarkType checks whether the given mark type is allowed in this node.
func (*NodeType) AllowsMarks ¶
AllowsMarks tests whether the given set of marks are allowed in this node.
func (*NodeType) Create ¶
func (nt *NodeType) Create(attrs map[string]interface{}, content interface{}, marks []*Mark) (*Node, error)
Create a Node of this type. The given attributes are checked and defaulted (you can pass null to use the type's defaults entirely, if no required attributes exist). content may be a Fragment, a node, an array of nodes, or null. Similarly marks may be null to default to the empty set of marks.
func (*NodeType) CreateAndFill ¶
CreateAndFill is like create, but see if it is necessary to add nodes to the start or end of the given fragment to make it fit the node. If no fitting wrapping can be found, return null. Note that, due to the fact that required nodes can always be created, this will always succeed if you pass null or Fragment.empty as content.
:: (?Object, ?union<Fragment, Node, [Node]>, ?Mark) → ?Node
func (*NodeType) CreateChecked ¶
CreateChecked is like create, but check the given content against the node type's content restrictions, and throw an error if it doesn't match.
:: (?Object, ?union<Fragment, Node, [Node]>, ?Mark) → Node
func (*NodeType) HasRequiredAttrs ¶ added in v0.4.6
HasRequiredAttrs tells you whether this node type has any required attributes.
func (*NodeType) IsAtom ¶ added in v0.4.12
IsAtom returns true when this node is an atom, i.e. when it does not have directly editable content.
func (*NodeType) ValidContent ¶
ValidContent returns true if the given fragment is valid content for this node type with the given attributes.
type ReplaceError ¶
type ReplaceError struct {
Message string
}
ReplaceError is the error type raised by Node.replace when given an invalid replacement.
func NewReplaceError ¶
func NewReplaceError(message string, args ...interface{}) *ReplaceError
NewReplaceError is the constructor for ReplaceError.
type ResolvedPos ¶
type ResolvedPos struct { // The position that was resolved. Pos int Path []interface{} // The number of levels the parent node is from the root. If this // position points directly into the root node, it is 0. If it // points into a top-level paragraph, 1, and so on. Depth int // The offset this position has into its parent node. ParentOffset int }
ResolvedPos means resolved position. You can resolve a position to get more information about it. Objects of this class represent such a resolved position, providing various pieces of context information, and some helper methods.
Throughout this interface, methods that take an optional depth parameter will interpret undefined as this.depth and negative numbers as this.depth + value.
func NewResolvedPos ¶
func NewResolvedPos(pos int, path []interface{}, parentOffset int) *ResolvedPos
NewResolvedPos is the constructor of ResolvedPos.
func (*ResolvedPos) After ¶
func (r *ResolvedPos) After(depth ...int) (int, error)
After is the (absolute) position directly after the wrapping node at the given level, or the original position when depth is this.depth + 1.
func (*ResolvedPos) Before ¶
func (r *ResolvedPos) Before(depth ...int) (int, error)
Before is the (absolute) position directly before the wrapping node at the given level, or, when depth is this.depth + 1, the original position.
func (*ResolvedPos) Doc ¶
func (r *ResolvedPos) Doc() *Node
Doc is the root node in which the position was resolved.
func (*ResolvedPos) End ¶
func (r *ResolvedPos) End(depth ...int) int
End is the (absolute) position at the end of the node at the given level.
func (*ResolvedPos) Index ¶
func (r *ResolvedPos) Index(depth ...int) int
Index returns the index into the ancestor at the given level. If this points at the 3rd node in the 2nd paragraph on the top level, for example, p.index(0) is 1 and p.index(1) is 2.
func (*ResolvedPos) IndexAfter ¶
func (r *ResolvedPos) IndexAfter(depth ...int) int
IndexAfter returns the index pointing after this position into the ancestor at the given level.
func (*ResolvedPos) Marks ¶
func (r *ResolvedPos) Marks() []*Mark
Marks gets the marks at this position, factoring in the surrounding marks' inclusive property. If the position is at the start of a non-empty node, the marks of the node after it (if any) are returned.
func (*ResolvedPos) Node ¶
func (r *ResolvedPos) Node(depth ...int) *Node
Node returns the ancestor node at the given level. p.node(p.depth) is the same as p.parent.
func (*ResolvedPos) NodeAfter ¶
func (r *ResolvedPos) NodeAfter() (*Node, error)
NodeAfter gets the node directly after the position, if any. If the position points into a text node, only the part of that node after the position is returned.
func (*ResolvedPos) NodeBefore ¶
func (r *ResolvedPos) NodeBefore() (*Node, error)
NodeBefore gets the node directly before the position, if any. If the position points into a text node, only the part of that node before the position is returned.
func (*ResolvedPos) Parent ¶
func (r *ResolvedPos) Parent() *Node
Parent returns the parent node that the position points into. Note that even if a position points into a text node, that node is not considered the parent—text nodes are ‘flat’ in this model, and have no content.
func (*ResolvedPos) SharedDepth ¶
func (r *ResolvedPos) SharedDepth(pos int) int
SharedDepth is the depth up to which this position and the given (non-resolved) position share the same parent nodes.
func (*ResolvedPos) Start ¶
func (r *ResolvedPos) Start(depth ...int) int
Start is the (absolute) position at the start of the node at the given level.
func (*ResolvedPos) TextOffset ¶
func (r *ResolvedPos) TextOffset() int
TextOffset returns, when this position points into a text node, the distance between the position and the start of the text node. Will be zero for positions that point between nodes.
type Schema ¶
type Schema struct { // The spec on which the schema is based. Spec *SchemaSpec // An object mapping the schema's node names to node type objects. Nodes []*NodeType // A map from mark names to mark type objects. Marks []*MarkType }
Schema is a a document schema: it holds node and mark type objects for the nodes and marks that may occur in conforming documents, and provides functionality for creating and deserializing such documents.
func NewSchema ¶
func NewSchema(spec *SchemaSpec) (*Schema, error)
NewSchema constructs a schema from a schema specification.
func (*Schema) MarkFromJSON ¶
MarkFromJSON deserializes a mark from its JSON representation.
func (*Schema) MarkType ¶ added in v0.2.0
MarkType returns the MarkType with the given name in this schema.
func (*Schema) Node ¶
Node creates a node in this schema. The type may be a string or a NodeType instance. Attributes will be extended with defaults, content may be a Fragment, null, a Node, or an array of nodes.
:: (union<string, NodeType>, ?Object, ?union<Fragment, Node, [Node]>, ?Mark) → Node
func (*Schema) NodeFromJSON ¶
NodeFromJSON deserializes a node from its JSON representation.
type SchemaSpec ¶
type SchemaSpec struct { // The node types in this schema. Maps names to NodeSpec objects that // describe the node type associated with that name. Their order is // significant—it determines which parse rules take precedence by default, // and which nodes come first in a given group. Nodes []*NodeSpec // The mark types that exist in this schema. The order in which they are // provided determines the order in which mark sets are sorted and in which // parse rules are tried. Marks []*MarkSpec // The name of the default top-level node for the schema. Defaults to "doc". TopNode string }
SchemaSpec is an object describing a schema, as passed to the Schema constructor.
func SchemaSpecFromJSON ¶ added in v0.3.0
func SchemaSpecFromJSON(raw map[string]interface{}) SchemaSpec
SchemaSpecFromJSON returns a SchemaSpec from a JSON representation.
func (SchemaSpec) MarshalJSON ¶
func (s SchemaSpec) MarshalJSON() ([]byte, error)
MarshalJSON creates a JSON representation of the SchemaSpec.
func (*SchemaSpec) UnmarshalJSON ¶
func (s *SchemaSpec) UnmarshalJSON(buf []byte) error
UnmarshalJSON parses a JSON representation of a SchemaSpec.
type Slice ¶
type Slice struct { // Fragment The slice's content. Content *Fragment // The open depth at the start. OpenStart int // number The open depth at the end. OpenEnd int }
Slice represents a piece cut out of a larger document. It stores not only a fragment, but also the depth up to which nodes on both side are ‘open’ (cut through).
func NewSlice ¶
NewSlice creates a slice. When specifying a non-zero open depth, you must make sure that there are nodes of at least that depth at the appropriate side of the fragment—i.e. if the fragment is an empty paragraph node, openStart and openEnd can't be greater than 1.
It is not necessary for the content of open nodes to conform to the schema's content constraints, though it should be a valid start/end/middle for such a node, depending on which sides are open.
func SliceFromJSON ¶ added in v0.2.0
SliceFromJSON deserializes a slice from its JSON representation.
func (*Slice) RemoveBetween ¶
RemoveBetween removes content between the two given positions.