Document helpers

Document helpers work on the document as a whole: they collect its headings for a table of contents, keep an empty node at its end, and give its nodes unique IDs.

When you use them

  • Navigation. Table of contents collects the headings and other anchors of a document with their depth, ID, and scroll state, so you can render your own table of contents.
  • A node after the last block. Trailing node adds a node after the last block node in the editor.
  • Referring to nodes. Unique ID gives each node of the types you configure an ID that stays with it when people split, merge, paste, or undo.

How they work

  • They are extensions. They work on the nodes of the document and don't add nodes or marks of their own. Extensions
  • Trailing node comes with the StarterKit. It is part of the StarterKit; Table of contents and Unique ID you add yourself.
  • You render the table of contents. Its onUpdate callback receives the anchors, and you render them with any framework or with plain DOM code.
  • IDs on the server. generateTocIds and generateUniqueIds add IDs to a JSON document without an editor instance.
  • With collaboration, mount after sync. When you use Unique ID with Collaboration, mount the editor only after the collaboration provider has synced.