Custom Plugins
Extend the editor with your own toolbar buttons, keyboard shortcuts, patterns, components, and parsers. Plugins implement the EditorPlugin interface.
Plugin Structure
A plugin is a plain object implementing the EditorPlugin interface:
JSX Component Plugin — components + defineComponent()
For JSX-style MDX tags, use components with defineComponent(). It gives you strictly-typed props, automatic preview rendering, syntax highlighting, and autocomplete — all from a single declaration. No regex required.
MDX usage
Once the plugin is registered, authors write standard JSX in the editor:
Pattern-based Plugin — patterns
Use patterns only when the syntax cannot be expressed as a JSX tag — e.g. fenced code blocks (```mermaid), directive fences (:::type), or math delimiters ($…$). The example above (my-plugin.ts) shows this approach end-to-end.
Registering a Plugin
Pass your plugin object in the plugins array alongside built-in plugin factories:
Plugin Context
The PluginContext passed to init() and destroy() provides access to the editor and dynamic registration methods:
Editor API
Inside toolbar actions and via ctx.editor, you have access to the full editor API:
Dynamic Registration
Plugins can be registered or removed at runtime via the editor instance:
EditorPlugin Reference
| Property | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Unique identifier for the plugin. |
init | (ctx: PluginContext) => void | Promise<void> | No | Called once when the plugin is registered. Receives the PluginContext. |
destroy | (ctx: PluginContext) => void | No | Called when the plugin is removed. Clean up resources here. |
toolbarItems | ToolbarItemConfig[] | No | Toolbar buttons contributed by this plugin. |
shortcuts | ShortcutConfig[] | No | Keyboard shortcuts. Key combos like "ctrl+shift+w". |
patterns | RendererConfig[] | No | Raw regex-based renderers — escape hatch for non-JSX syntax (e.g. fenced code blocks, :::type admonitions, $...$ math). Prefer components for JSX-style MDX. |
components | RendererConfig[] | No | Declarative MDX component definitions using defineComponent(). Syntax-highlight tokens and autocomplete completions are auto-registered for every listed tag. Preferred over patterns for JSX-style components. |
parsers | ParserConfig[] | No | Custom block parsers for extended MDX syntax. |
completions | CompletionItem[] | No | Static autocomplete items contributed by this plugin. Items with kind "snip" expand on Tab with $1 cursor position. |
provideTokens | PluginTokenProvider | No | Per-line syntax highlighter. Return TokenSegment[] to colour MDX syntax. Use componentTagTokens() for JSX components — handles tag names, attribute names/values, boolean attributes, and multi-line tags. |
styles | string | No | CSS string injected into the editor. |
dependencies | string[] | No | Names of plugins that must be registered first. |
© 2026 SynclineMDX Editor. All rights reserved.