@@ -58,13 +58,14 @@ export function createNodeFromContent(
58
58
}
59
59
60
60
if ( isTextContent ) {
61
- let schemaToUse = schema
62
- let hasInvalidContent = false
63
- let invalidContent = ''
64
61
65
- // Only ever check for invalid content if we're supposed to throw an error
62
+ // Check for invalid content
66
63
if ( options . errorOnInvalidContent ) {
67
- schemaToUse = new Schema ( {
64
+ let hasInvalidContent = false
65
+ let invalidContent = ''
66
+
67
+ // A copy of the current schema with a catch-all node at the end
68
+ const contentCheckSchema = new Schema ( {
68
69
topNode : schema . spec . topNode ,
69
70
marks : schema . spec . marks ,
70
71
// Prosemirror's schemas are executed such that: the last to execute, matches last
@@ -88,19 +89,26 @@ export function createNodeFromContent(
88
89
} ,
89
90
} ) ,
90
91
} )
91
- }
92
92
93
- const parser = DOMParser . fromSchema ( schemaToUse )
93
+ if ( options . slice ) {
94
+ DOMParser . fromSchema ( contentCheckSchema ) . parseSlice ( elementFromString ( content ) , options . parseOptions )
95
+ } else {
96
+ DOMParser . fromSchema ( contentCheckSchema ) . parse ( elementFromString ( content ) , options . parseOptions )
97
+ }
94
98
95
- const response = options . slice
96
- ? parser . parseSlice ( elementFromString ( content ) , options . parseOptions ) . content
97
- : parser . parse ( elementFromString ( content ) , options . parseOptions )
99
+ if ( options . errorOnInvalidContent && hasInvalidContent ) {
100
+ throw new Error ( '[tiptap error]: Invalid HTML content' , { cause : new Error ( `Invalid element found: ${ invalidContent } ` ) } )
101
+ }
102
+ }
103
+
104
+ const parser = DOMParser . fromSchema ( schema )
98
105
99
- if ( options . errorOnInvalidContent && hasInvalidContent ) {
100
- throw new Error ( '[tiptap error]: Invalid HTML content' , { cause : new Error ( `Invalid element found: ${ invalidContent } ` ) } )
106
+ if ( options . slice ) {
107
+ return parser . parseSlice ( elementFromString ( content ) , options . parseOptions ) . content
101
108
}
102
109
103
- return response
110
+ return parser . parse ( elementFromString ( content ) , options . parseOptions )
111
+
104
112
}
105
113
106
114
return createNodeFromContent ( '' , schema , options )
0 commit comments