Custom extensions
Most editor features in ProseKit are themselves extensions. When the official ones don't fit, you write your own and union them in.
When you actually need a custom extension
Section titled “When you actually need a custom extension”| Goal | Reach for | | ---------------------------------------- | --------------------------------------------------- | | Bind a key | defineKeymap | | Run a command | defineCommands | | Listen to events | defineKeyDownHandler, definePasteHandler, … | | Add a node or mark | defineNodeSpec, defineMarkSpec | | Add an attribute to an existing node | defineNodeAttr | | Drop in a raw ProseMirror plugin | definePlugin | | Render a node with a framework component | Custom node views |
Most of those are one-call extensions. You only need a "full" custom extension when you're combining several of them.
Anatomy of a typical extension
Section titled “Anatomy of a typical extension”The official extensions follow a consistent shape. Here's what defineBold looks like, simplified:
Three building blocks (spec, commands, keymap) joined by union. Same pattern works for any feature: define each piece in isolation, then compose. See Concepts → Extensions for the full story.
Adding to an existing editor
Section titled “Adding to an existing editor”Or, after the editor exists, hot-add it with editor.use(extension) (see Concepts → The Editor).
Publishing as a package
Section titled “Publishing as a package”Ready to share your extension on npm? The prosekit-extension-template repository is a complete, working example. It packages a small YouTube-embed extension and wires up everything you need to ship it and release new versions: a TypeScript build, browser-based tests, and an automated pipeline that publishes to npm from Conventional Commits via release-please and npm trusted publishing (OIDC).
Clone it, rename the package in package.json, and follow its README to cut your first release.
See also
Section titled “See also”- Concepts → Extensions
- Custom node views
prosekit/corereferenceprosekit-extension-template: a publishable extension package with an automated npm release setup