Skip to content
GitHubDiscord

prosekit/extensions/enter-rule

Options for EnterRuleHandler.

from: number

The start position of the matched text.

match: RegExpExecArray

The matched result from the regular expression.

state: EditorState

The current editor state.

to: number

The end position of the matched text.


Options for defineTextBlockEnterRule.

attrs?: null | Attrs | (match: RegExpMatchArray) => null | Attrs

Attributes to set on the node. If a function is provided, it will be called with the matched result from the regular expression.

regex: RegExp

The regular expression to match against. It should end with $.

stop?: boolean

Whether to stop further handlers from being called if this rule is triggered.

true

type: string | NodeType

The node type to replace the matched text with.

type EnterRuleHandler = (options: EnterRuleHandlerOptions) => Transaction | null


type EnterRuleOptions = { handler: EnterRuleHandler; regex: RegExp; stop?: boolean; }

Options for defineEnterRule.

handler: EnterRuleHandler

A function to be called when an enter rule is triggered.

regex: RegExp

The regular expression to match against. It should end with $.

stop?: boolean

Whether to stop further handlers from being called if this rule is triggered.

false

function defineEnterRule(options: EnterRuleOptions): PlainExtension

Defines an enter rule. An enter rule applies when the text directly in front of the cursor matches regex and user presses Enter. The regex should end with $.


function defineTextBlockEnterRule(options: TextBlockEnterRuleOptions): PlainExtension

Defines an enter rule that replaces the matched text with a block node.

See also defineEnterRule.