Skip to main content

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 the Marks namespace or createYooptaMark to define custom marks.

Accessing the API

Import the Marks 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.
Parameters:
  • 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 — Slate Range; 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).
Parameters:
  • editor — Editor instance (required).
  • options.type — Mark type (required).
  • options.value — Value to set (required); e.g. true for bold, '#ff0000' for color.
  • options.at — Block index or array of indices.
  • options.blockId — Block ID or array of IDs.
  • options.selection — Slate Range to apply to.

remove

Removes a mark from the current selection or from specified blocks. Alias: Marks.remove (same as removeMark).
Parameters:
  • 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 — Slate Range to remove from.

toggle

Toggles a mark in the current selection or in specified blocks (adds if absent, removes if present).
Parameters:
  • 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 — Slate Range to toggle in.

isActive

Returns whether a mark is active in the current selection or in a given block.
Parameters:
  • editor — Editor instance (required).
  • options.type — Mark type to check (required).
  • options.at — Block index; default: current selection path.
  • options.blockId — Block ID.
Returns: true if the mark is active, false otherwise.

getValue

Returns the value of a mark in the current selection or in a given block.
Parameters:
  • editor — Editor instance (required).
  • options.type — Mark type (required).
  • options.at — Block index; default: current selection path.
  • options.blockId — Block ID.
Returns: Mark value or null if not set.

getAll

Returns all marks in the current selection or in a given block. Alias: Marks.getAll (same as getMarks).
Parameters:
  • editor — Editor instance (required).
  • options.at — Block index; default: current selection path.
  • options.blockId — Block ID.
Returns: Object of mark type → value, or null if no Slate context.

clear

Removes all marks from the current selection or from specified blocks.
Parameters:
  • editor — Editor instance (required).
  • options.at — Block index or array of indices; when omitted and no selection, uses current selection or selected blocks.
  • options.blockId — Block ID or array of IDs.
  • options.selection — Slate Range to clear.

Defining custom marks: createYooptaMark

Use createYooptaMark to define a mark that you then pass to createYooptaEditor({ marks: [...] }). The mark has a type, optional hotkey, and a render function.
Parameters:
  • 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).
Returns: A YooptaMark object to add to the marks array when creating the editor.