Skip to content

Commit 2926d71

Browse files
authored
fix(BaseSchema): fixed definition of an empty string during serialization (#571)
1 parent 0749cb3 commit 2926d71

File tree

1 file changed

+18
-2
lines changed
  • src/extensions/base/BaseSchema/BaseSchemaSpecs

1 file changed

+18
-2
lines changed

src/extensions/base/BaseSchema/BaseSchemaSpecs/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type {NodeSpec} from 'prosemirror-model';
1+
import type {Node, NodeSpec} from 'prosemirror-model';
22

33
import type {ExtensionAuto} from '../../../../core';
44
import {nodeTypeFactory} from '../../../../utils/schema';
@@ -69,7 +69,7 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
6969
An empty line is added only if there is some content in the parent element.
7070
This is necessary in order to prevent an empty document with empty lines
7171
*/
72-
if (opts.preserveEmptyRows && !node.content.size) {
72+
if (opts.preserveEmptyRows && isEmptyString(node)) {
7373
let isParentEmpty = true;
7474

7575
for (let index = 0; index < parent.content.childCount; index++) {
@@ -92,3 +92,19 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
9292
},
9393
}));
9494
};
95+
96+
const isEmptyString = (node: Node) => {
97+
if (!node.content.size) {
98+
return true;
99+
}
100+
101+
if (
102+
node.childCount === 1 &&
103+
node.child(0).type.name === 'text' &&
104+
node.child(0).text?.trim() === ''
105+
) {
106+
return true;
107+
}
108+
109+
return false;
110+
};

0 commit comments

Comments
 (0)