Skip to content

Function: defineExtension() ​

ts
function defineExtension<Args>(factory): (...args) => Extension;

Define an extension. The factory receives the options the user passes and returns what the extension contributes.

Type Parameters ​

Type Parameter
Args extends unknown[]

Parameters ​

ParameterType
factory(...args) => ExtensionSpec

Returns ​

(...args) => Extension

Example ​

ts
export const highlight = defineExtension((options: { color?: string } = {}) => ({
  name: 'highlight',
  marks: { highlight: { parseDOM: [{ tag: 'mark' }], toDOM: () => ['mark', 0] } },
}))

createEditor({ extensions: [...basic(), highlight({ color: 'yellow' })], label: 'Text' })