Methods
BlockNote provides a number of methods to interact with the editor.
undo
The undo method is used to undo the last action.
editor.undo();redo
The redo method is used to redo the last action.
editor.redo();exec
The exec method executes a prosemirror command. This is mostly for backwards compatibility with older code.
You should prefer the transact method when possible, as it will automatically handle the dispatching of the transaction and work across blocknote transactions.
// Example of a custom command
function insertTextCommand(state: EditorState, dispatch: EditorDispatch, view: EditorView) {
if (dispatch) {
dispatch(state.tr.insertText("Hello, world!"));
}
}
editor.exec(insertTextCommand);canExec
The canExec method checks if a prosemirror command can be executed.
const canExecute = editor.canExec(insertTextCommand);transact
The transact method executes a prosemirror transaction. See the low-level APIs section for more information.
editor.transact((tr) => {
tr.insertText("Hello, world!");
});pasteHTML
The pasteHTML method pastes HTML into the editor.
editor.pasteHTML("<p>Hello, world!</p>");pasteText
The pasteText method pastes text into the editor.
editor.pasteText("Hello, world!");pasteMarkdown
The pasteMarkdown method pastes markdown into the editor.
editor.pasteMarkdown("**Hello, world!**");