Skip to content
GitHubDiscord

prosekit/extensions/paste-rule

The options for defineMarkPasteRule.

regex: RegExp

The regular expression to match against. It must have a g flag to match all instances of the mark.

type: string | MarkType

The mark type to apply to the matched text.

getAttrs?: (match: RegExpExecArray) => undefined | null | false | Attrs

A function used to compute attributes to set on the mark created by this rule. When it returns false, the rule won't match. When it returns null or undefined, that is interpreted as an empty/default set of attributes.

null

shouldSkip?: (node: ProseMirrorNode) => boolean

Optional function to determine if a text node should be skipped. Default behavior: skip code nodes and nodes that already have the target mark.


Options for PasteRuleHandler.

slice: Slice

The slice to be pasted.

view: EditorView

The editor view.

plain: boolean

Whether the pasted content is treated as plain text. This is true when the Shift key is held when pasting.


Options for definePasteRule.

handler: PasteRuleHandler

A function to be called when a paste rule is triggered.

type PasteRuleHandler = (options: PasteRuleHandlerOptions) => Slice

Can be used to transform pasted or dragged-and-dropped content before it is applied to the document.

function defineMarkPasteRule(options: MarkPasteRuleOptions): PlainExtension

Defines a paste rule that applies marks based on regex patterns.


function definePasteRule(options: PasteRuleOptions): PlainExtension

Defines a paste rule. This rule allows you to modify pasted or dragged content before it is inserted into the document.