Overview
Mark commands allow you to add, remove, and toggle inline formatting (like bold, italic, links, etc.) in your ProseKit editor.addMark()
Adds a mark with the given attributes to the current selection or specified range.Function Signature
Parameters
The type of the mark to add. Can be a string name or a MarkType instance.
The attributes of the mark to add
The start position in the document. Defaults to the start of the current selection.
The end position in the document. Defaults to the end of the current selection.
Return Value
A ProseMirror command that returns
true if the mark was successfully added, false otherwise.Examples
Add Bold Mark to Selection
Add Link Mark with Attributes
Add Mark to Custom Range
removeMark()
Removes a mark from the current selection or specified range.Function Signature
Parameters
The type of the mark to remove
If provided, only remove marks with precisely these attributes. Otherwise, remove all marks of the given type.
The start position in the document. Defaults to the start of the current selection.
The end position in the document. Defaults to the end of the current selection.
Return Value
A ProseMirror command that returns
true if the mark was successfully removed, false otherwise.Examples
Remove Bold Mark
Remove Specific Link
Remove All Links
toggleMark()
Toggles a mark - adds it if not present, removes it if present.Function Signature
Parameters
The mark type to toggle
The optional attributes to set on the mark
Controls behavior when part of the selection has the mark and part doesn’t:
true: remove the markfalse: add the mark
Whether the command should act on the content of inline nodes marked as atoms that are completely covered by the selection
Return Value
A ProseMirror command that returns
true if the mark was successfully toggled, false otherwise.Examples
Toggle Bold
Toggle with Attributes
Custom Toggle Behavior
expandMark()
Expands the current selection to include the full range of a mark.Function Signature
Parameters
The type of mark to expand to
Return Value
A ProseMirror command that returns
true if the selection was successfully expanded, false otherwise.Example
unsetMark()
Removes stored marks from the selection. This affects what marks will be applied to newly typed text.Function Signature
Parameters
Return Value
A ProseMirror command that returns
true if the mark was successfully unset, false otherwise.Example
Usage with Editor Commands
When you define marks in your extension, ProseKit automatically generates command actions on the editor:Common Patterns
Creating a Toolbar Button
Keyboard Shortcut Handler
Conditional Mark Application
See Also
- Node Commands - Commands for manipulating block nodes
- Selection Commands - Commands for manipulating selections
- defineMarkSpec - Define custom marks