File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed
src/extensions/base/BaseSchema/BaseSchemaSpecs Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change 1
- import type { NodeSpec } from 'prosemirror-model' ;
1
+ import type { Node , NodeSpec } from 'prosemirror-model' ;
2
2
3
3
import type { ExtensionAuto } from '../../../../core' ;
4
4
import { nodeTypeFactory } from '../../../../utils/schema' ;
@@ -69,7 +69,7 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
69
69
An empty line is added only if there is some content in the parent element.
70
70
This is necessary in order to prevent an empty document with empty lines
71
71
*/
72
- if ( opts . preserveEmptyRows && ! node . content . size ) {
72
+ if ( opts . preserveEmptyRows && isEmptyString ( node ) ) {
73
73
let isParentEmpty = true ;
74
74
75
75
for ( let index = 0 ; index < parent . content . childCount ; index ++ ) {
@@ -92,3 +92,19 @@ export const BaseSchemaSpecs: ExtensionAuto<BaseSchemaSpecsOptions> = (builder,
92
92
} ,
93
93
} ) ) ;
94
94
} ;
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
+ } ;
You can’t perform that action at this time.
0 commit comments