fix: preserve whitespace when using insertContent command
This commit is contained in:
@@ -20,7 +20,11 @@ declare module '@tiptap/core' {
|
|||||||
|
|
||||||
export const insertContentAt: RawCommands['insertContentAt'] = (position, value) => ({ tr, dispatch, editor }) => {
|
export const insertContentAt: RawCommands['insertContentAt'] = (position, value) => ({ tr, dispatch, editor }) => {
|
||||||
if (dispatch) {
|
if (dispatch) {
|
||||||
const content = createNodeFromContent(value, editor.schema)
|
const content = createNodeFromContent(value, editor.schema, {
|
||||||
|
parseOptions: {
|
||||||
|
preserveWhitespace: 'full',
|
||||||
|
},
|
||||||
|
})
|
||||||
const { from, to } = typeof position === 'number'
|
const { from, to } = typeof position === 'number'
|
||||||
? { from: position, to: position }
|
? { from: position, to: position }
|
||||||
: position
|
: position
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
export default function elementFromString(value: string): HTMLElement {
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user