Plugin Signature
A plugin conforms to theEditorPlugin type:
Editor instance and should perform all its setup work synchronously — subscribing to events, appending UI elements, patching methods, etc. The return value is ignored.
What Plugins Can Do
Because plugins receive the full editor instance, they can:- Subscribe to events using
editor.on()and clean up witheditor.off()to react to content changes, errors, view switches, and more. - Read and write content by calling
editor.getHTML(),editor.getText(), andeditor.setHTML(). - Append UI to the editor root by accessing
editor.root— the underlyingcontenteditableelement — and inserting sibling or wrapper nodes. - Call any public method including
editor.focus(),editor.blur(),editor.setTheme(), andeditor.use()to compose behaviour across plugins. - Add side effects such as starting a
MutationObserver, registering keyboard shortcuts viadocument.addEventListener, or initializing third-party libraries that operate on the editor’s DOM.
Installing a Plugin
Via the constructor
Pass an array of plugin functions to theplugins option. Plugins run synchronously in array order immediately after the editor mounts:
Via editor.use()
Install a plugin at any point after initialization using editor.use(). This is useful for lazy-loading plugins or for conditionally applying them based on runtime state:
Plugins run synchronously — whether registered in the
plugins constructor option or installed via editor.use(). All setup code inside a plugin executes before the next JavaScript statement after the constructor or use() call returns.Full Example: Word Count Plugin
The following plugin appends a live word count badge below the editor and keeps it updated on every content change:Accessing the Editor Root
editor.root is the contenteditable HTMLElement that hosts the document. You can use it as an anchor for additional DOM nodes, event delegation, or position-aware UI like floating toolbars: