diff --git a/packages/core/src/commands/insertContent.ts b/packages/core/src/commands/insertContent.ts index 9b8db913..5acd40b7 100644 --- a/packages/core/src/commands/insertContent.ts +++ b/packages/core/src/commands/insertContent.ts @@ -1,3 +1,4 @@ +import { CreateNodeFromContentOptions } from '../helpers/createNodeFromContent' import { RawCommands, Content } from '../types' declare module '@tiptap/core' { @@ -6,11 +7,11 @@ declare module '@tiptap/core' { /** * Insert a node or string of HTML at the current position. */ - insertContent: (value: Content) => ReturnType, + insertContent: (value: Content, options?: CreateNodeFromContentOptions) => ReturnType, } } } -export const insertContent: RawCommands['insertContent'] = value => ({ tr, commands }) => { - return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value) +export const insertContent: RawCommands['insertContent'] = (value, options) => ({ tr, commands }) => { + return commands.insertContentAt({ from: tr.selection.from, to: tr.selection.to }, value, options) } diff --git a/packages/core/src/commands/insertContentAt.ts b/packages/core/src/commands/insertContentAt.ts index 22e6fc7d..f5a1a4f1 100644 --- a/packages/core/src/commands/insertContentAt.ts +++ b/packages/core/src/commands/insertContentAt.ts @@ -1,4 +1,4 @@ -import createNodeFromContent from '../helpers/createNodeFromContent' +import createNodeFromContent, { CreateNodeFromContentOptions } from '../helpers/createNodeFromContent' import selectionToInsertionEnd from '../helpers/selectionToInsertionEnd' import { RawCommands, @@ -12,17 +12,18 @@ declare module '@tiptap/core' { /** * Insert a node or string of HTML at a specific position. */ - insertContentAt: (position: number | Range, value: Content) => ReturnType, + insertContentAt: (position: number | Range, value: Content, options?: CreateNodeFromContentOptions) => ReturnType, } } } -export const insertContentAt: RawCommands['insertContentAt'] = (position, value) => ({ tr, dispatch, editor }) => { +export const insertContentAt: RawCommands['insertContentAt'] = (position, value, options) => ({ tr, dispatch, editor }) => { if (dispatch) { const content = createNodeFromContent(value, editor.schema, { parseOptions: { preserveWhitespace: 'full', }, + ...(options || {}) }) // don’t dispatch an empty fragment because this can lead to strange errors