Marks API
The Marks API lets you apply, update, remove, and query text formatting (bold, italic, color, highlight, etc.) in the editor. Marks are applied to the current selection or to specific blocks. Use theMarks namespace or createYooptaMark to define custom marks.
Accessing the API
Import theMarks namespace and createYooptaMark from @yoopta/editor:
Marks API methods are not on the editor instance — use the
Marks namespace. Marks must be registered via createYooptaEditor({ marks: [...] }).Type Definitions
Methods
update
Sets the value of a mark in the current selection or in specified blocks.editor— Editor instance (required).options.type— Mark type, e.g.'color','fontSize'(required).options.value— Value to set (required); e.g.'#ff0000',16.options.at— Block index or array of indices; default: current selection path or selected blocks.options.blockId— Block ID or array of IDs.options.selection— SlateRange; when set, applies to this range instead of blocks.
add
Adds a mark (or sets its value) in the current selection or in specified blocks. Alias:Marks.add (same as addMark).
editor— Editor instance (required).options.type— Mark type (required).options.value— Value to set (required); e.g.truefor bold,'#ff0000'for color.options.at— Block index or array of indices.options.blockId— Block ID or array of IDs.options.selection— SlateRangeto apply to.
remove
Removes a mark from the current selection or from specified blocks. Alias:Marks.remove (same as removeMark).
editor— Editor instance (required).options.type— Mark type to remove (required).options.at— Block index or array of indices.options.blockId— Block ID or array of IDs.options.selection— SlateRangeto remove from.
toggle
Toggles a mark in the current selection or in specified blocks (adds if absent, removes if present).editor— Editor instance (required).options.type— Mark type to toggle (required).options.at— Block index or array of indices.options.blockId— Block ID or array of IDs.options.selection— SlateRangeto toggle in.
isActive
Returns whether a mark is active in the current selection or in a given block.editor— Editor instance (required).options.type— Mark type to check (required).options.at— Block index; default: current selection path.options.blockId— Block ID.
true if the mark is active, false otherwise.
getValue
Returns the value of a mark in the current selection or in a given block.editor— Editor instance (required).options.type— Mark type (required).options.at— Block index; default: current selection path.options.blockId— Block ID.
null if not set.
getAll
Returns all marks in the current selection or in a given block. Alias:Marks.getAll (same as getMarks).
editor— Editor instance (required).options.at— Block index; default: current selection path.options.blockId— Block ID.
null if no Slate context.
clear
Removes all marks from the current selection or from specified blocks.editor— Editor instance (required).options.at— Block index or array of indices; when omitted and noselection, uses current selection or selected blocks.options.blockId— Block ID or array of IDs.options.selection— SlateRangeto clear.
Defining custom marks: createYooptaMark
UsecreateYooptaMark to define a mark that you then pass to createYooptaEditor({ marks: [...] }). The mark has a type, optional hotkey, and a render function.
params.type— Unique mark type string (required).params.hotkey— Optional keyboard shortcut, e.g.'mod+b'for bold.params.render— React component that receives Slate render props and renders the marked text (required).
YooptaMark object to add to the marks array when creating the editor.