Overview
ProseKit provides several APIs for defining custom extensions that add nodes, marks, and functionality to your editor. Extensions are the building blocks of ProseKit editors.Node Extensions
defineNodeSpec()
Defines a node type into the editor schema.Parameters
Configuration for the node specification
The name of the node type
Whether this is the top-level node type. Only one node type can be the top-level node in a schema.
The attributes that nodes of this type get
The content expression for this node type (e.g., “inline*”, “block+”)
The group or groups this node belongs to (e.g., “block”, “inline”)
Rules for parsing DOM content into this node
Function to serialize this node to DOM
Example
defineNodeAttr()
Defines an attribute for a node type.Parameters
The name of the node type
The name of the attribute
The default value for this attribute
Whether the attribute should be kept when the node is split. Set to
true to inherit the attribute when splitting the node by pressing Enter.Returns the attribute key and value to be set on the HTML element
Parses the attribute value from the DOM
Example
Mark Extensions
defineMarkSpec()
Defines a mark type into the editor schema.Parameters
Configuration for the mark specification
The name of the mark type
The attributes that marks of this type get
Rules for parsing DOM content into this mark
Function to serialize this mark to DOM
Whether this mark should be active when the cursor is at its end
The marks that this mark excludes
The group or groups this mark belongs to
Whether this mark should span multiple nodes
Example
defineMarkAttr()
Defines an attribute for a mark type.Parameters
The name of the mark type
The name of the attribute
The default value for this attribute
Returns the attribute key and value to be set on the HTML element
Parses the attribute value from the DOM
Example
Command Extensions
defineCommands()
Defines custom commands for the editor.Extension Type Safety
ProseKit extensions are fully type-safe. When you define nodes, marks, or commands, TypeScript will infer the correct types throughout your editor:See Also
- union - Combine multiple extensions
- createEditor - Create an editor instance
- Priority - Extension priority system