Skip to content
GitHubDiscord

prosekit/core

ProseKit extension priority.

Enumeration Member Value

default

2

high

3

highest

4

low

1

lowest

0

Type Parameter Default type

E extends Extension

any

get commands(): ExtractCommandActions<E>

All CommandActions defined by the editor.

ExtractCommandActions<E>

get focused(): boolean

Whether the editor is focused.

boolean

get marks(): ExtractMarkActions<E>

All MarkActions defined by the editor.

ExtractMarkActions<E>

get mounted(): boolean

Whether the editor is mounted.

boolean

get nodes(): ExtractNodeActions<E>

All NodeActions defined by the editor.

ExtractNodeActions<E>

get schema(): Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>

The editor schema.

Schema<ExtractNodeNames<E>, ExtractMarkNames<E>>

get state(): EditorState

The editor’s current state.

EditorState

get view(): EditorView

The editor view.

EditorView

blur(): void

Blur the editor.

canExec(command: Command): boolean

Check if the given command can be executed. Return true if the command can be executed, otherwise false.

exec(command: Command): boolean

Execute the given command. Return true if the command was successfully executed, otherwise false.

focus(): void

Focus the editor.

getDocHTML(options?: getDocHTMLOptions): string

Return a HTML string representing the editor’s current document.

getDocJSON(): NodeJSON

Return a JSON object representing the editor’s current document.

mount(place: undefined | null | HTMLElement): void

Mount the editor to the given HTML element. Pass null or undefined to unmount the editor.

setContent(content: string | ProseMirrorNode | NodeJSON | HTMLElement, selection?: Selection | "start" | SelectionJSON | "end"): void

Update the editor’s document and selection.

unmount(): void

Unmount the editor. This is equivalent to mount(null).

updateState(state: EditorState): void

Update the editor’s state.

This is an advanced method. Use it only if you have a specific reason to directly manipulate the editor’s state.

use(extension: Extension): VoidFunction

Register an extension to the editor. Return a function to unregister the extension.

attrs?: null | Attrs

The attributes of the mark to add.

from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.

type: string | MarkType

The type of the mark to add.


A function to apply a command to the editor. It will return true if the command was applied, and false otherwise.

It also has a canExec method to check if the command can be applied.

Type Parameter Default type

Args extends any[]

any[]

CommandAction(…args: Args): boolean

Execute the current command. Return true if the command was successfully executed, otherwise false.

canApply(…args: Args): boolean

An alias for canExec.

Use canExec instead.

canExec(…args: Args): boolean

Check if the current command can be executed. Return true if the command can be executed, otherwise false.


defaultContent?: string | NodeJSON | HTMLElement

The starting document to use when creating the editor. It can be a ProseMirror node JSON object, a HTML string, or a HTML element instance.

defaultDoc?: NodeJSON

A JSON object representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultHTML?: string | HTMLElement

A HTML element or a HTML string representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultSelection?: SelectionJSON

A JSON object representing the starting selection to use when creating the editor. It’s only used when defaultContent is also provided.


document?: Document

The Document object to use for DOM operations. If not provided, defaults to the current browser’s document object. Useful for server-side rendering or testing environments.


context?: ResolvedPos

A set of additional nodes to count as context when parsing, above the given top node.

DOMParser?: typeof DOMParser

findPositions?: object[]

When given, the parser will, beside parsing the content, record the document positions of the given DOM positions. It will do so by writing to the objects, adding a pos property that holds the document position. DOM positions that are not in the parsed content will not be written to.

from?: number

The child node index to start parsing from.

preserveWhitespace?: boolean | "full"

By default, whitespace is collapsed as per HTML’s rules. Pass true to preserve whitespace, but normalize newlines to spaces, and "full" to preserve whitespace entirely.

to?: number

The child node index to stop parsing at.

topMatch?: ContentMatch

Provide the starting content match that content parsed into the top node is matched against.

topNode?: ProseMirrorNode

By default, the content is parsed into the schema’s default top node type. You can pass this option to use the type and attributes from a different node as the top container.


DOMSerializer?: object


Type Parameter

E extends Extension

defaultContent?: string | NodeJSON | HTMLElement

The starting document to use when creating the editor. It can be a ProseMirror node JSON object, a HTML string, or a HTML element instance.

defaultDoc?: NodeJSON

A JSON object representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultHTML?: string | HTMLElement

A HTML element or a HTML string representing the starting document to use when creating the editor.

Use defaultContent instead.

defaultSelection?: SelectionJSON

A JSON object representing the starting selection to use when creating the editor. It’s only used when defaultContent is also provided.

extension: E

The extension to use when creating the editor.


type: string | MarkType

The type of the mark to expand.


Type Parameter Default type

T extends ExtensionTyping<any, any, any>

ExtensionTyping<any, any, any>

_type?: T

extension: Extension<ExtensionTyping<any, any, any>> | Extension<ExtensionTyping<any, any, any>>[]

priority?: Priority

schema: null | Schema<any, any>

The schema that this extension represents.


Type Parameter

Input

Output

get reducer(): FacetReducer<Input, Output>

FacetReducer<Input, Output>


depth: number

The depth of the node.

node: ProseMirrorNode

The closest parent node that satisfies the predicate.

pos: number

The position directly before the node.

start: number

The position at the start of the node.


Options for defineHistory.

depth?: number

The amount of history events that are collected before the oldest events are discarded.

200

newGroupDelay?: number

The delay in milliseconds between changes after which a new group should be started.

250

pos?: number

The position to insert the node at. By default it will insert after the current selection.


attrs?: Attrs

When type is provided, the attributes of the node to insert.

node?: ProseMirrorNode

The node to insert. Either this or type must be provided.

pos?: number

The position to insert the node at. By default it will be the anchor position of current selection.

type?: string | NodeType

The type of the node to insert. Either this or node must be provided.


schema: Schema

The editor schema to use.


[key: string]: Command


A function for applying a mark with optional attributes and any number of children.

It also has a isActive method for checking if the mark is active in the current editor selection.

Type Parameter Default type

Attrs extends AnyAttrs

AnyAttrs

MarkAction(attrs: null | Attrs, …children: NodeChild[]): ProseMirrorNode[]

Applies a mark with attributes and any number of children.

MarkAction(…children: NodeChild[]): ProseMirrorNode[]

Applies a mark with any number of children.

isActive: (attrs?: Attrs) => boolean

Checks if the mark is active in the current editor selection. If the optional attrs parameter is provided, it will check if the mark is active with the given attributes.


MarkAttrOptions<MarkName, AttrName, AttrType>

Section titled “MarkAttrOptions<MarkName, AttrName, AttrType>”
Type Parameter Default type

MarkName extends string

string

AttrName extends string

string

AttrType

any

attr: AttrName

The name of the attribute.

default?: AttrType

The default value for this attribute, to use when no explicit value is provided. Attributes that have no default must be provided whenever a node or mark of a type that has them is created.

parseDOM?: (node: HTMLElement) => AttrType

Parses the attribute value from the DOM.

toDOM?: (value: AttrType) => undefined | null | [string, string]

Returns the attribute key and value to be set on the HTML element.

If the returned key is "style", the value is a string of CSS properties and will be prepended to the existing style attribute on the DOM node.

type: MarkName

The name of the mark type.

validate?: string | (value: unknown) => void

A function or type name used to validate values of this attribute. This will be used when deserializing the attribute from JSON, and when running Node.check. When a function, it should raise an exception if the value isn’t of the expected type or shape. When a string, it should be a |-separated string of primitive types ("number", "string", "boolean", "null", and "undefined"), and the library will raise an error when the value is not one of those types.


Type Parameter Default type

MarkName extends string

string

Attrs extends AnyAttrs

AnyAttrs

[key: string]: any

Mark specs can include additional properties that can be inspected through MarkType.spec when working with the mark.

attrs?: { [K in string | number | symbol]: AttrSpec<Attrs[K]> }

The attributes that marks of this type get.

code?: boolean

Marks the content of this span as being code, which causes some commands and extensions to treat it differently.

excludes?: string

Determines which other marks this mark can coexist with. Should be a space-separated strings naming other marks or groups of marks. When a mark is added to a set, all marks that it excludes are removed in the process. If the set contains any mark that excludes the new mark but is not, itself, excluded by the new mark, the mark can not be added an the set. You can use the value "_" to indicate that the mark excludes all marks in the schema.

Defaults to only being exclusive with marks of the same type. You can set it to an empty string (or any string not containing the mark’s own name) to allow multiple marks of a given type to coexist (as long as they have different attributes).

group?: string

The group or space-separated groups to which this mark belongs.

inclusive?: boolean

Whether this mark should be active when the cursor is positioned at its end (or at its start when that is also the start of the parent node). Defaults to true.

name: MarkName

The name of the mark type.

parseDOM?: readonly ParseRule[]

Associates DOM parser information with this mark (see the corresponding node spec field). The mark field in the rules is implied.

spanning?: boolean

Determines whether marks of this type can span multiple adjacent nodes when serialized to DOM/HTML. Defaults to true.

toDOM?: (mark: Mark, inline: boolean) => DOMOutputSpec

Defines the default way marks of this type should be serialized to DOM/HTML. When the resulting spec contains a hole, that is where the marked content is placed. Otherwise, it is appended to the top node.


constructor: MarkViewConstructor

name: string


A function for creating a node with optional attributes and any number of children.

It also has a isActive method for checking if the node is active in the current editor selection.

Type Parameter Default type

Attrs extends AnyAttrs

AnyAttrs

NodeAction(attrs: null | Attrs, …children: NodeChild[]): ProseMirrorNode

Creates a node with attributes and any number of children.

NodeAction(…children: NodeChild[]): ProseMirrorNode

Creates a node with any number of children.

isActive: (attrs?: Attrs) => boolean

Checks if the node is active in the current editor selection. If the optional attrs parameter is provided, it will check if the node is active with the given attributes.


NodeAttrOptions<NodeName, AttrName, AttrType>

Section titled “NodeAttrOptions<NodeName, AttrName, AttrType>”
Type Parameter Default type

NodeName extends string

string

AttrName extends string

string

AttrType

any

attr: AttrName

The name of the attribute.

default?: AttrType

The default value for this attribute, to use when no explicit value is provided. Attributes that have no default must be provided whenever a node or mark of a type that has them is created.

parseDOM?: (node: HTMLElement) => AttrType

Parses the attribute value from the DOM.

splittable?: boolean

Whether the attribute should be kept when the node is split. Set it to true if you want to inherit the attribute from the previous node when splitting the node by pressing Enter.

undefined

toDOM?: (value: AttrType) => undefined | null | [string, string]

Returns the attribute key and value to be set on the HTML element.

If the returned key is "style", the value is a string of CSS properties and will be prepended to the existing style attribute on the DOM node.

type: NodeName

The name of the node type.

validate?: string | (value: unknown) => void

A function or type name used to validate values of this attribute. This will be used when deserializing the attribute from JSON, and when running Node.check. When a function, it should raise an exception if the value isn’t of the expected type or shape. When a string, it should be a |-separated string of primitive types ("number", "string", "boolean", "null", and "undefined"), and the library will raise an error when the value is not one of those types.


A JSON representation of the prosemirror node.

attrs?: Record<string, any>

content?: NodeJSON[]

marks?: object[]

text?: string

type: string


Type Parameter Default type

NodeName extends string

string

Attrs extends AnyAttrs

AnyAttrs

[key: string]: any

Node specs may include arbitrary properties that can be read by other code via NodeType.spec.

atom?: boolean

Can be set to true to indicate that, though this isn’t a leaf node, it doesn’t have directly editable content and should be treated as a single unit in the view.

attrs?: { [key in string | number | symbol]: AttrSpec<Attrs[key]> }

The attributes that nodes of this type get.

code?: boolean

Can be used to indicate that this node contains code, which causes some commands to behave differently.

content?: string

The content expression for this node, as described in the schema guide. When not given, the node does not allow any content.

defining?: boolean

When enabled, enables both definingAsContext and definingForContent.

definingAsContext?: boolean

Determines whether this node is considered an important parent node during replace operations (such as paste). Non-defining (the default) nodes get dropped when their entire content is replaced, whereas defining nodes persist and wrap the inserted content.

definingForContent?: boolean

In inserted content the defining parents of the content are preserved when possible. Typically, non-default-paragraph textblock types, and possibly list items, are marked as defining.

disableDropCursor?: boolean | (view: EditorView, pos: object, event: DragEvent) => boolean

draggable?: boolean

Determines whether nodes of this type can be dragged without being selected. Defaults to false.

group?: string

The group or space-separated groups to which this node belongs, which can be referred to in the content expressions for the schema.

inline?: boolean

Should be set to true for inline nodes. (Implied for text nodes.)

isolating?: boolean

When enabled (default is false), the sides of nodes of this type count as boundaries that regular editing operations, like backspacing or lifting, won’t cross. An example of a node that should probably have this enabled is a table cell.

leafText?: (node: ProseMirrorNode) => string

Defines the default way a leaf node of this type should be serialized to a string (as used by Node.textBetween and Node.textContent).

linebreakReplacement?: boolean

A single inline node in a schema can be set to be a linebreak equivalent. When converting between block types that support the node and block types that don’t but have whitespace set to "pre", setBlockType will convert between newline characters to or from linebreak nodes as appropriate.

marks?: string

The marks that are allowed inside of this node. May be a space-separated string referring to mark names or groups, "_" to explicitly allow all marks, or "" to disallow marks. When not given, nodes with inline content default to allowing all marks, other nodes default to not allowing marks.

name: NodeName

The name of the node type.

parseDOM?: readonly TagParseRule[]

Associates DOM parser information with this node, which can be used by DOMParser.fromSchema to automatically derive a parser. The node field in the rules is implied (the name of this node will be filled in automatically). If you supply your own parser, you do not need to also specify parsing rules in your schema.

selectable?: boolean

Controls whether nodes of this type can be selected as a node selection. Defaults to true for non-text nodes.

toDebugString?: (node: ProseMirrorNode) => string

Defines the default way a node of this type should be serialized to a string representation for debugging (e.g. in error messages).

toDOM?: (node: ProseMirrorNode) => DOMOutputSpec

Defines the default way a node of this type should be serialized to DOM/HTML (as used by DOMSerializer.fromSchema). Should return a DOM node or an array structure that describes one, with an optional number zero (“hole”) in it to indicate where the node’s content should be inserted.

For text nodes, the default is to create a text DOM node. Though it is possible to create a serializer where text is rendered differently, this is not supported inside the editor, so you shouldn’t override that in your text node spec.

topNode?: boolean

Whether this is the top-level node type. Only one node type can be the top-level node type in a schema.

whitespace?: "pre" | "normal"

Controls way whitespace in this a node is parsed. The default is "normal", which causes the DOM parser to collapse whitespace in normal mode, and normalize it (replacing newlines and such with spaces) otherwise. "pre" causes the parser to preserve spaces inside the node. When this option isn’t given, but code is true, whitespace will default to "pre". Note that this option doesn’t influence the way the node is rendered—that should be handled by toDOM and/or styling.


constructor: NodeViewConstructor

name: string


attrs?: null | Attrs

If attrs is given, remove precisely the mark with the given attrs. Otherwise, remove all marks of the given type.

from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.

type: string | MarkType

The type of the mark to remove.


pos?: number

The document position to start searching node. By default it will be the anchor position of current selection.

type: string | NodeType

The type of the node to remove.


A JSON representation of the prosemirror selection.

anchor: number

head: number

type: string


attrs?: null | Attrs

from?: number

to?: number

type: string | NodeType


attrs: Attrs

The attributes to set.

pos?: number

The position of the node. Defaults to the position of the wrapping node containing the current selection.

type: string | NodeType | string[] | NodeType[]

The type of node to set the attributes of.

If current node is not of this type, the command will do nothing.


A JSON representation of the prosemirror state.

doc: NodeJSON

The main ProseMirror doc.

selection: SelectionJSON

The current selection.


A JSON representation of the prosemirror step.

[x: string]: unknown

stepType: string

The type of the step.


attrs?: null | Attrs

The optional attributes to set on the mark.

enterInlineAtoms?: boolean

Whether the command should act on the content of inline nodes marked as atoms that are completely covered by a selection range.

true

removeWhenPresent?: boolean

Controls whether, when part of the selected range has the mark already and part doesn’t, the mark is removed (true) or added (false).

false

type: string | MarkType

The mark type to toggle.


attrs?: null | Attrs

The attributes of the node to toggle.

type: string | NodeType

The type of the node to toggle.


attrs?: null | Attrs

The attributes of the node to toggle.

type: string | NodeType

The type of the node to toggle.


from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.


from?: number

The start position of the document. By default it will be the start position of current selection.

to?: number

The end position of the document. By default it will be the end position of current selection.


attrs?: null | Attrs

Optional attributes to apply to the node.

nodeType?: NodeType

Use nodeSpec instead.

type: string | NodeType

The node type to wrap the selected textblock with.

type AnyAttrs = Attrs

An object holding the attributes of a node.


type AttrSpec<AttrType> = { default?: AttrType; validate?: string | (value: unknown) => void; }

Type Parameter Default type

AttrType

any

default?: AttrType

The default value for this attribute, to use when no explicit value is provided. Attributes that have no default must be provided whenever a node or mark of a type that has them is created.

validate?: string | (value: unknown) => void

A function or type name used to validate values of this attribute. This will be used when deserializing the attribute from JSON, and when running Node.check. When a function, it should raise an exception if the value isn’t of the expected type or shape. When a string, it should be a |-separated string of primitive types ("number", "string", "boolean", "null", and "undefined"), and the library will raise an error when the value is not one of those types.


type ClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void


type ClickOnHandler = (view: EditorView, pos: number, node: ProseMirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void


type DocChangeHandler = (view: EditorView, prevState: EditorState) => void

A function that is called when the editor document is changed.


type DOMEventHandler<Event> = (view: EditorView, event: DOMEventMap[Event]) => boolean | void

A function to handle the events fired on the editable DOM element. Returns true to indicate that it handled the given event. you are responsible for calling preventDefault yourself (or not, if you want to allow the default behavior).

Type Parameter Default type

Event extends keyof DOMEventMap

string


type DoubleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void


type DoubleClickOnHandler = (view: EditorView, pos: number, node: ProseMirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void


type DropHandler = (view: EditorView, event: DragEvent, slice: Slice, moved: boolean) => boolean | void


type ExtractCommandActions<E> = ToCommandAction<ExtractCommands<E>>

Extracts the CommandActions from an extension type.

Type Parameter

E extends Extension


type ExtractCommandAppliers<E> = ExtractCommandActions<E>

Type Parameter

E extends Extension

Use ExtractCommandActions instead.


type ExtractCommandCreators<E> = ToCommandCreators<ExtractCommands<E>>

Type Parameter

E extends Extension


type ExtractMarkActions<E> = ToMarkAction<ExtractMarks<E>>

Extracts the MarkActions from an extension type.

Type Parameter

E extends Extension


type ExtractMarks<E> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>["Marks"]>>

Type Parameter

E extends Extension


type ExtractNodeActions<E> = ToNodeAction<ExtractNodes<E>>

Extracts the NodeActions from an extension type.

Type Parameter

E extends Extension


type ExtractNodes<E> = SimplifyDeeper<SimplifyUnion<ExtractTyping<E>["Nodes"]>>

Type Parameter

E extends Extension


type FocusChangeHandler = (hasFocus: boolean) => void

A function that is called when the editor gains or loses focus.


type KeyDownHandler = (view: EditorView, event: KeyboardEvent) => boolean | void


type KeyPressHandler = (view: EditorView, event: KeyboardEvent) => boolean | void


type MarkBuilder = MarkAction

Use type MarkAction instead.


type MountHandler = (view: EditorView) => void

A function that is called when the editor view is mounted.


type NodeBuilder = NodeAction

Use type NodeAction instead.


type NodeChild = ProseMirrorNode | string | NodeChild[]

Available children parameters for NodeAction and MarkAction.


type PasteHandler = (view: EditorView, event: ClipboardEvent, slice: Slice) => boolean | void


type ScrollToSelectionHandler = (view: EditorView) => boolean


type TextInputHandler = (view: EditorView, from: number, to: number, text: string) => boolean | void


type TripleClickHandler = (view: EditorView, pos: number, event: MouseEvent) => boolean | void


type TripleClickOnHandler = (view: EditorView, pos: number, node: ProseMirrorNode, nodePos: number, event: MouseEvent, direct: boolean) => boolean | void


type UnmountHandler = () => void

A function that is called when the editor view is unmounted.


type UpdateHandler = (view: EditorView, prevState: EditorState) => void

A function that is called when the editor state is updated.

const canUseRegexLookbehind: () => boolean


const clsx: (…args: (string | boolean | null | undefined)[]) => string = clsxLite

A utility for constructing className strings conditionally.

It is a re-export of clsx/lite with stricter types.

function addMark(options: AddMarkOptions): Command

Returns a command that adds the given mark with the given attributes.


function createEditor<E>(options: EditorOptions<E>): Editor<E>


function defineBaseCommands(): BaseCommandsExtension

Add some base commands


function defineBaseKeymap(options?: object): PlainExtension

Defines some basic key bindings.


function defineClickHandler(handler: ClickHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleClick


function defineClickOnHandler(handler: ClickOnHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleClickOn


function defineCommands<T>(commands: T): Extension<{ Commands: { [K in string | number | symbol]: Parameters<T[K]> }; }>


function defineDefaultState(options: DefaultStateOptions): PlainExtension

Define a default state for the editor.


function defineDoc(): DocExtension

Use the following import instead:

import { defineDoc } from 'prosekit/extensions/doc'

function defineDocChangeHandler(handler: DocChangeHandler): PlainExtension

Registers a event handler that is called when the editor document is changed.


function defineDOMEventHandler<Event>(event: Event, handler: DOMEventHandler<Event>): PlainExtension

Register a new event handler for the given event type.


function defineDoubleClickHandler(handler: DoubleClickHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClick


function defineDoubleClickOnHandler(handler: DoubleClickOnHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleDoubleClickOn


function defineDropHandler(handler: DropHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleDrop


function defineFocusChangeHandler(handler: FocusChangeHandler): PlainExtension

Registers a event handler that is called when the editor gains or loses focus.


function defineHistory(options: HistoryOptions): HistoryExtension

Add undo/redo history to the editor.


function defineKeyDownHandler(handler: KeyDownHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyDown


function defineKeymap(keymap: Keymap): PlainExtension


function defineKeyPressHandler(handler: KeyPressHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleKeyPress


function defineMarkAttr<MarkType, AttrName, AttrType>(options: MarkAttrOptions<MarkType, AttrName, AttrType>): Extension<{ Marks: { [K in string]: AttrType }; }>


function defineMarkSpec<Mark, Attrs>(options: MarkSpecOptions<Mark, Attrs>): Extension<{ Marks: { [K in string]: Attrs }; }>


function defineMarkView(options: MarkViewOptions): Extension


function defineMountHandler(handler: MountHandler): PlainExtension

Registers a event handler that is called when the editor view is mounted.


function defineNodeAttr<NodeType, AttrName, AttrType>(options: NodeAttrOptions<NodeType, AttrName, AttrType>): Extension<{ Nodes: { [K in string]: { [K in string]: AttrType } }; }>

Defines an attribute for a node type.


function defineNodeSpec<Node, Attrs>(options: NodeSpecOptions<Node, Attrs>): Extension<{ Nodes: { [K in string]: Attrs }; }>

Defines a node type.


function defineNodeView(options: NodeViewOptions): Extension


function defineParagraph(): ParagraphSpecExtension

Defines a paragraph node spec as the highest priority, because it should be the default block node for most cases.

Use the following import instead:

import { defineParagraph } from 'prosekit/extensions/paragraph'

function definePasteHandler(handler: PasteHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handlePaste


function definePlugin(plugin: ProseMirrorPlugin<any> | ProseMirrorPlugin<any>[] | (context: object) => ProseMirrorPlugin<any> | ProseMirrorPlugin<any>[]): PlainExtension

Adds a ProseMirror plugin to the editor.


function defineScrollToSelectionHandler(handler: ScrollToSelectionHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleScrollToSelection


function defineText(): TextExtension

Use the following import instead:

import { defineText } from 'prosekit/extensions/text'

function defineTextInputHandler(handler: TextInputHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleTextInput


function defineTripleClickHandler(handler: TripleClickHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClick


function defineTripleClickOnHandler(handler: TripleClickOnHandler): PlainExtension

See https://prosemirror.net/docs/ref/#view.EditorProps.handleTripleClickOn


function defineUnmountHandler(handler: UnmountHandler): PlainExtension

Registers a event handler that is called when the editor view is unmounted.


function defineUpdateHandler(handler: UpdateHandler): PlainExtension

Registers a event handler that is called when the editor state is updated.


function elementFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): HTMLElement

Parse a ProseMirror document JSON object to a HTML element.

const json = { type: 'doc', content: [{ type: 'paragraph' }] }
const element = elementFromJSON(json, { schema: editor.schema })

function elementFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): HTMLElement

Serialize a ProseMirror node to a HTML element.

const node = editor.state.doc
const element = elementFromNode(node)

function expandMark(options: ExpandMarkOptions): Command

Expands the selection to include the entire mark at the current position.


function findParentNode(predicate: (node: ProseMirrorNode) => boolean, $pos: ResolvedPos): undefined | FindParentNodeResult

Find the closest parent node that satisfies the predicate.


function findParentNodeOfType(type: string | NodeType, $pos: ResolvedPos): undefined | FindParentNodeResult

Finds the closest parent node that matches the given node type.


function htmlFromJSON(json: NodeJSON, options: JSONParserOptions & DOMSerializerOptions & DOMDocumentOptions): string

Parse a ProseMirror document JSON object to a HTML string.

const json = { type: 'doc', content: [{ type: 'paragraph' }] }
const html = htmlFromJSON(json, { schema: editor.schema })

function htmlFromNode(node: ProseMirrorNode, options?: DOMSerializerOptions & DOMDocumentOptions): string

Serialize a ProseMirror node to a HTML string

const node = document.getElementById('content')
const html = htmlFromNode(node)

function insertDefaultBlock(options?: InsertDefaultBlockOptions): Command

Returns a command that inserts a default block after current selection or at the given position.


function insertNode(options: InsertNodeOptions): Command

Returns a command that inserts the given node at the current selection or at the given position.


function isAllSelection(value: Selection): value is AllSelection

Checks if the given object is a AllSelection instance.


function isFragment(value: unknown): value is ProseMirrorFragment

Checks if the given object is a Fragment instance.


function isMark(value: unknown): value is Mark

Checks if the given object is a Mark instance.


function isNodeSelection(value: Selection): value is NodeSelection

Checks if the given object is a NodeSelection instance.


function isProseMirrorNode(value: unknown): value is ProseMirrorNode

Checks if the given object is a ProseMirrorNode instance.


function isSelection(value: unknown): value is Selection

Checks if the given object is a Selection instance.


function isSlice(value: unknown): value is Slice

Checks if the given object is a Slice instance.


function isTextSelection(value: Selection): value is TextSelection

Checks if the given object is a TextSelection instance.


function jsonFromHTML(html: string, options: DOMDocumentOptions & DOMParserOptions & JSONParserOptions): NodeJSON

Parse a HTML string to a ProseMirror document JSON object.

const html = '<p>Hello, world!</p>'
const json = jsonFromHTML(html, { schema: editor.schema })

function jsonFromNode(node: ProseMirrorNode): NodeJSON

Return a JSON object representing this node.

const node = editor.state.doc
const json = jsonFromNode(node)

function jsonFromState(state: EditorState): StateJSON

Return a JSON object representing this state.

const state = editor.state
const json = jsonFromState(state)

function nodeFromElement(element: Node, options: DOMParserOptions & JSONParserOptions): ProseMirrorNode

Parse a HTML element to a ProseMirror node.

const element = document.getElementById('content')
const node = nodeFromElement(element, { schema: editor.schema })

</dd>

</dl>

***

### nodeFromHTML() {#nodefromhtml}

<dl>

<dt>

<code data-typedoc-declaration><i>function</i> <i></i> <a id="nodefromhtml-2" href="#nodefromhtml-2">nodeFromHTML</a>(`html`: `string`, `options`: [`DOMParserOptions`](#domparseroptions) & [`JSONParserOptions`](#jsonparseroptions) & [`DOMDocumentOptions`](#domdocumentoptions)): [`ProseMirrorNode`](pm/model.md#prosemirrornode)</code>

</dt>

<dd>

Parse a HTML string to a ProseMirror node.

#### Example

```ts
const html = '<p>Hello, world!</p>'
const node = nodeFromHTML(html, { schema: editor.schema })

</dd>

</dl>

***

### nodeFromJSON() {#nodefromjson}

<dl>

<dt>

<code data-typedoc-declaration><i>function</i> <i></i> <a id="nodefromjson-2" href="#nodefromjson-2">nodeFromJSON</a>(`json`: [`NodeJSON`](#nodejson), `options`: [`JSONParserOptions`](#jsonparseroptions)): [`ProseMirrorNode`](pm/model.md#prosemirrornode)</code>

</dt>

<dd>

Parse a JSON object to a ProseMirror node.

#### Example

```ts
const json = { type: 'doc', content: [{ type: 'paragraph' }] }
const node = nodeFromJSON(json, { schema: editor.schema })

function removeMark(options: RemoveMarkOptions): Command

Returns a command that removes the given mark.


function removeNode(options: RemoveNodeOptions): Command

Returns a command to remove the nearest ancestor node of a specific type from the current position.


function setBlockType(options: SetBlockTypeOptions): Command

Returns a command that tries to set the selected textblocks to the given node type with the given attributes.


function setNodeAttrs(options: SetNodeAttrsOptions): Command

Returns a command that set the attributes of the current node.


function setSelectionAround(tr: Transaction, pos: number): void


function stateFromJSON(json: StateJSON, options: JSONParserOptions): EditorState

Parse a JSON object to a ProseMirror state.

const json = { state: { type: 'doc', content: [{ type: 'paragraph' }], selection: { type: 'text', from: 1, to: 1 } } }
const state = stateFromJSON(json, { schema: editor.schema })

function toggleMark(options: ToggleMarkOptions): Command

Returns a command that toggles the given mark with the given attributes.


function toggleNode(options: ToggleNodeOptions): Command

Returns a command that set the selected textblocks to the given node type with the given attributes.


function toggleWrap(options: ToggleWrapOptions): Command

Toggle between wrapping an inactive node with the provided node type, and lifting it up into its parent.


function union<E>(…exts: E): Union<E>

Merges multiple extensions into one. You can pass multiple extensions as arguments or a single array containing multiple extensions.

If no extensions are provided.

function defineFancyNodes() {
  return union(
    defineFancyParagraph(),
    defineFancyHeading(),
  )
}
function defineFancyNodes() {
  return union([
    defineFancyParagraph(),
    defineFancyHeading(),
  ])
}

function union<E>(exts: E): Union<E>

Merges multiple extensions into one. You can pass multiple extensions as arguments or a single array containing multiple extensions.

If no extensions are provided.

function defineFancyNodes() {
  return union(
    defineFancyParagraph(),
    defineFancyHeading(),
  )
}
function defineFancyNodes() {
  return union([
    defineFancyParagraph(),
    defineFancyHeading(),
  ])
}

function unsetBlockType(options?: UnsetBlockTypeOptions): Command

Returns a command that set the type of all textblocks between the given range to the default type (usually paragraph).


function unsetMark(options?: UnsetMarkOptions): Command

Returns a command that removes all marks.


function withPriority<T>(extension: T, priority: Priority): T

Return an new extension with the given priority.

import { Priority, withPriority } from 'prosekit/core'

const extension = withPriority(defineMyExtension(), Priority.high)

function wrap(options: WrapOptions): Command

Returns a command that wraps the selected textblock with the given node type.