Documentation
¶
Index ¶
- func Must[T any](v T, err error) T
- func RegisterSchema(s Schema)
- type Attribute
- type Attrs
- type ContentMatch
- type Edge
- type Expr
- type Fragment
- type Mark
- type MarkSpec
- type MarkType
- func (mt MarkType) Create(attrs map[string]any) Mark
- func (m MarkType) Eq(other MarkType) bool
- func (mt MarkType) Excludes(other MarkType) bool
- func (mt MarkType) IsInSet(set []MarkType) MarkType
- func (mt MarkType) MarshalJSON() ([]byte, error)
- func (mt MarkType) RemoveFromSet(set []MarkType) []MarkType
- func (mt MarkType) String() string
- func (mt *MarkType) UnmarshalJSON(b []byte) error
- type MarkTypeName
- type Node
- func (n Node) Child(index int) *Node
- func (n Node) ChildCount() int
- func (n Node) Clone() Node
- func (n Node) Descendants(f func(n Node, pos int, parent *Node, index int) bool)
- func (n Node) FirstChild() *Node
- func (n Node) IsAtom() bool
- func (n Node) IsInline() bool
- func (n Node) IsLeaf() bool
- func (n Node) IsText() bool
- func (n Node) MarshalJSON() ([]byte, error)
- func (n Node) MaybeChild(index int) *Node
- func (n Node) NodeSize() int
- func (n Node) Replace(from, to int, s Slice) (Node, error)
- func (n Node) Resolve(pos int) (ResolvedPos, error)
- func (n Node) Slice(from, to int, includeParents bool) (Slice, error)
- func (n Node) String() string
- func (n Node) WithMarks(m []Mark) Node
- type NodeSpec
- type NodeType
- func (n NodeType) AllowsMarkType(markType MarkType) bool
- func (n NodeType) CheckContent(f Fragment) error
- func (n NodeType) Create(attrs map[string]any, marks []Mark, content ...Node) (Node, error)
- func (n NodeType) Eq(other NodeType) bool
- func (n NodeType) Format(s fmt.State, verb rune)
- func (n NodeType) MarshalJSON() ([]byte, error)
- func (n *NodeType) UnmarshalJSON(b []byte) error
- type NodeTypeName
- type ResolvedPos
- func (r ResolvedPos) End(depth int) int
- func (r ResolvedPos) Index(depth int) int
- func (r ResolvedPos) IndexAfter(depth int) int
- func (r ResolvedPos) Node(depth int) Node
- func (r ResolvedPos) NodeAfter() *Node
- func (r ResolvedPos) NodeBefore() *Node
- func (r ResolvedPos) Parent() Node
- func (r ResolvedPos) SharedDepth(pos int) int
- func (r ResolvedPos) Start(depth int) int
- func (r ResolvedPos) String() string
- func (r ResolvedPos) TextOffset() bool
- type Schema
- type SchemaSpec
- type Slice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterSchema ¶
func RegisterSchema(s Schema)
RegisterSchema registers a schema in the global store. It is used for unmarshalling Nodes and Marks.
Types ¶
type ContentMatch ¶
type ContentMatch struct {
Next []contentMatchNode
ValidEnd bool
}
func EmptyContentMatch ¶
func EmptyContentMatch() *ContentMatch
func (ContentMatch) Empty ¶
func (c ContentMatch) Empty() bool
func (*ContentMatch) InlineContent ¶
func (c *ContentMatch) InlineContent() bool
func (ContentMatch) String ¶
func (c ContentMatch) String() string
type Expr ¶
type Expr struct {
Type string
// for `choice` and `seq`
Exprs []Expr
Value NodeType
// for `choice`, `seq`, `+`, `*`, `range` and `?`
Expr *Expr
// for `+`, `range` as well as `*` and `?`
Min int
Max int
}
TODO: handle `seq` properly
type Fragment ¶
Fragment represents a node's collection of child nodes its represented as an array of nodes in JSON, but we cache the size of the fragment for operational reasons.
func NewFragment ¶
func (Fragment) ChildCount ¶
func (Fragment) MarshalJSON ¶
func (*Fragment) UnmarshalJSON ¶
type MarkSpec ¶
type MarkSpec struct {
// The attributes this mark can have.
Attrs map[string]Attribute
// Whether this mark should be active at its end.
Inclusive bool
// Determines which other marks this can coexist with.
Excludes string
// The group or groups this mark belongs to.
Group string
// Whether this mark can span multiple nodes.
Spanning bool
// Additional spec properties.
Extra map[string]any
}
type MarkType ¶
type MarkType struct {
// The Name of the mark type.
Name MarkTypeName
// The schema this mark type is part of.
Schema Schema
// The spec for this mark type.
Spec MarkSpec
// The defined attributes for this mark type.
Attrs map[string]Attribute
// Marks excluded by this mark type.
Excluded []MarkType
// A mark instance with default attributes.
Instance *Mark
}
MarkType represents a mark on a node. Marks are used to represent things like whether a node is emphasized or part of a link.
func NewMarkType ¶
func NewMarkType(s Schema, name MarkTypeName, spec MarkSpec) MarkType
func (MarkType) MarshalJSON ¶
func (MarkType) RemoveFromSet ¶
Remove this mark type from a mark set, if present.
func (*MarkType) UnmarshalJSON ¶
type MarkTypeName ¶
type MarkTypeName string
type Node ¶
type Node struct {
// The type of this node.
Type NodeType `json:"type,omitempty"`
// A map of attribute names to values.
// The kind of attributes depends on the node type.
Attrs map[string]any `json:"attrs,omitempty"`
// The marks (things like whether it is emphasized or part of a link) applied to this node.
Marks []Mark `json:"marks,omitempty"`
// For text nodes, this contains the node's text content.
Text string `json:"text,omitempty"`
// The child node at the given index.
Content Fragment `json:"content,omitempty,omitzero"`
}
A node is a nested object which represents a fragment of a document. It roughly corresponds to an HTML element. Each node type has an associated string, known as its name. It may have any number of attributes, represented as a map from strings to arbitrary values.
- If the node type is text, it may have a string content property.
- If the node type is a non-leaf node, it may have a content property containing an array of child nodes.
- If the node type has inline content, it may have a marks property containing an array of marks.
- If the node type is a block node, it may have a attrs property containing a map of additional HTML attributes for the element.
The size of a node is either n.textLen(), 1, or the sum of the sizes of its children.
func (Node) ChildCount ¶
func (Node) Descendants ¶
Call the given callback for every descendant node. Doesn't descend into a node when the callback returns `false`.
func (Node) FirstChild ¶
func (Node) MarshalJSON ¶
func (Node) MaybeChild ¶
type NodeSpec ¶
type NodeSpec struct {
// The content expression for this node.
Content string
// The marks that are allowed inside this node.
Marks *string
// The group or groups this node belongs to.
Group string
// Should be true for inline nodes.
Inline bool
// Can be set to true for non-leaf nodes.
Atom bool
// The attributes this node can have.
Attrs map[string]Attribute
// Arbitrary additional properties.
Extra map[string]any
}
type NodeType ¶
type NodeType struct {
Name NodeTypeName
Spec NodeSpec
Schema Schema
Block bool
Text bool
Groups []string
Marks []MarkType
Attrs Attrs
DefaultAttrs map[string]any
ContentMatch ContentMatch
InlineContent bool
}
NodeType is the type of a slice content element
func NewNodeType ¶
func NewNodeType(name NodeTypeName) (NodeType, error)
func (NodeType) AllowsMarkType ¶
func (NodeType) CheckContent ¶
func (NodeType) Create ¶
CreateNodeType creates a node of the given type with the given attributes and content.
func (NodeType) MarshalJSON ¶
func (*NodeType) UnmarshalJSON ¶
type NodeTypeName ¶
type NodeTypeName string
type ResolvedPos ¶
type ResolvedPos struct {
Depth int
Pos int
ParentOffset int
// in the original JS implementation, paths is a any[] type
// they index it to retrieve the right one.
// nodepath is *3
NodePath []Node
// indexpath is *3+1
IndexPath []int
// offsetpath is *3+2 or *3-1
OffsetPath []int
}
func (ResolvedPos) End ¶
func (r ResolvedPos) End(depth int) int
func (ResolvedPos) Index ¶
func (r ResolvedPos) Index(depth int) int
func (ResolvedPos) IndexAfter ¶
func (r ResolvedPos) IndexAfter(depth int) int
The index pointing after this position into the ancestor at the given level.
func (ResolvedPos) Node ¶
func (r ResolvedPos) Node(depth int) Node
func (ResolvedPos) NodeAfter ¶
func (r ResolvedPos) NodeAfter() *Node
Get 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
Get 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
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
func (ResolvedPos) Start ¶
func (r ResolvedPos) Start(depth int) int
func (ResolvedPos) String ¶
func (r ResolvedPos) String() string
func (ResolvedPos) TextOffset ¶
func (r ResolvedPos) TextOffset() bool
When this position points into a text node, this returns 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 {
Spec SchemaSpec
TopNodeType *NodeType
Nodes map[NodeTypeName]NodeType
Marks map[MarkTypeName]MarkType
}
func NewSchema ¶
func NewSchema(spec SchemaSpec) (Schema, error)
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.
// The order in which they occur in the list is significant.
Nodes map[NodeTypeName]NodeSpec
// The mark types that exist in this schema.
Marks map[MarkTypeName]MarkSpec
// The name of the default top-level node for the schema.
TopNode NodeTypeName
// Don't register the schema in the global schema store.
DontRegister bool
}