Skip to content

prosekit/extensions/enter-rule

EnterRuleHandler()

EnterRuleHandler: (options) => Transaction | null

Parameters

options

options.from: number

The start position of the matched text.

options.match: RegExpExecArray

The matched result from the regular expression.

options.state: EditorState

The current editor state.

options.to: number

The end position of the matched text.

Returns

Transaction | null


EnterRuleOptions

EnterRuleOptions: object

Options for defineEnterRule.

Type declaration

NameTypeDescription
handlerEnterRuleHandlerA function to be called when an enter rule is triggered.
regexRegExpThe regular expression to match against. It should end with $.
stop?booleanWhether to stop further handlers from being called if this rule is triggered. Default false

TextBlockEnterRuleOptions

TextBlockEnterRuleOptions: object

Options for defineTextBlockEnterRule.

Type declaration

NameTypeDescription
attrs?Attrs | null | (match) => Attrs | nullAttributes to set on the node. If a function is provided, it will be called with the matched result from the regular expression.
regexRegExpThe regular expression to match against. It should end with $.
stop?booleanWhether to stop further handlers from being called if this rule is triggered. Default true
typestring | NodeTypeThe node type to replace the matched text with.

defineEnterRule()

defineEnterRule(options): 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 $.

Parameters

options: EnterRuleOptions

Returns

PlainExtension


defineTextBlockEnterRule()

defineTextBlockEnterRule(options): PlainExtension

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

See also defineEnterRule.

Parameters

options: TextBlockEnterRuleOptions

Returns

PlainExtension