diff --git a/.changeset/warm-yaks-speak.md b/.changeset/warm-yaks-speak.md new file mode 100644 index 000000000..a7b4512b5 --- /dev/null +++ b/.changeset/warm-yaks-speak.md @@ -0,0 +1,5 @@ +--- +"@tiptap/core": minor +--- + +add slice option to insertContentAt and insertContent function diff --git a/demos/src/Examples/Tables/React/index.spec.js b/demos/src/Examples/Tables/React/index.spec.js index 5202cdfcb..c6b508035 100644 --- a/demos/src/Examples/Tables/React/index.spec.js +++ b/demos/src/Examples/Tables/React/index.spec.js @@ -121,4 +121,20 @@ context('/src/Examples/Tables/React/', () => { expect(elements[1].innerText).to.equal('Column 2') }) }) + + it('should use parse function', () => { + cy.get('.tiptap').then(([{ editor }]) => { + editor.commands.insertContentAt(0, '
', { + applyInputRules: true, + slice: false, // to use parse function + }) + + cy.get('.tiptap table').should('exist').within(() => { + cy.get('colgroup').should('exist') + cy.get('tbody').should('exist') + cy.get('tr').should('exist') + cy.get('td').should('exist') + }) + }) + }) }) diff --git a/packages/core/src/commands/insertContent.ts b/packages/core/src/commands/insertContent.ts index 44210d69d..a5ae73f50 100644 --- a/packages/core/src/commands/insertContent.ts +++ b/packages/core/src/commands/insertContent.ts @@ -31,6 +31,12 @@ declare module '@tiptap/core' { updateSelection?: boolean; applyInputRules?: boolean; applyPasteRules?: boolean; + + /** + * Whether to use parseSlice function to parse the content. + * @default true + */ + slice?: boolean } ) => ReturnType; }; diff --git a/packages/core/src/commands/insertContentAt.ts b/packages/core/src/commands/insertContentAt.ts index 33c84524d..96d4223b2 100644 --- a/packages/core/src/commands/insertContentAt.ts +++ b/packages/core/src/commands/insertContentAt.ts @@ -50,6 +50,12 @@ declare module '@tiptap/core' { * Whether to throw an error if the content is invalid. */ errorOnInvalidContent?: boolean + + /** + * Whether to use parseSlice function to parse the content. + * @default true + */ + slice?: boolean }, ) => ReturnType } @@ -67,6 +73,7 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value, updateSelection: true, applyInputRules: false, applyPasteRules: false, + slice: true, ...options, } @@ -74,6 +81,7 @@ export const insertContentAt: RawCommands['insertContentAt'] = (position, value, try { content = createNodeFromContent(value, editor.schema, { + slice: options.slice, parseOptions: { preserveWhitespace: 'full', ...options.parseOptions,