mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-08-06 13:38:49 +08:00
fix: preserve whitespace when using insertContent command
This commit is contained in:
parent
c0cbd513f6
commit
8f101810fe
@ -20,7 +20,11 @@ declare module '@tiptap/core' {
|
||||
|
||||
export const insertContentAt: RawCommands['insertContentAt'] = (position, value) => ({ tr, dispatch, editor }) => {
|
||||
if (dispatch) {
|
||||
const content = createNodeFromContent(value, editor.schema)
|
||||
const content = createNodeFromContent(value, editor.schema, {
|
||||
parseOptions: {
|
||||
preserveWhitespace: 'full',
|
||||
},
|
||||
})
|
||||
const { from, to } = typeof position === 'number'
|
||||
? { from: position, to: position }
|
||||
: position
|
||||
|
@ -1,3 +1,6 @@
|
||||
export default function elementFromString(value: string): HTMLElement {
|
||||
return new window.DOMParser().parseFromString(value, 'text/html').body
|
||||
// add a wrapper to preserve leading and trailing whitespace
|
||||
const wrappedValue = `<body>${value}</body>`
|
||||
|
||||
return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user