mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-23 19:19:03 +08:00
This commit is contained in:
parent
f8d79da29b
commit
8d8d999803
5
.changeset/mean-pets-unite.md
Normal file
5
.changeset/mean-pets-unite.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@tiptap/core": patch
|
||||
---
|
||||
|
||||
fix: check for schema's nesting rules on contentCheck
|
@ -45,7 +45,13 @@ export function createNodeFromContent(
|
||||
return Fragment.fromArray(content.map(item => schema.nodeFromJSON(item)))
|
||||
}
|
||||
|
||||
return schema.nodeFromJSON(content)
|
||||
const node = schema.nodeFromJSON(content)
|
||||
|
||||
if (options.errorOnInvalidContent) {
|
||||
node.check()
|
||||
}
|
||||
|
||||
return node
|
||||
} catch (error) {
|
||||
if (options.errorOnInvalidContent) {
|
||||
throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error })
|
||||
|
@ -242,4 +242,25 @@ describe('createNodeFromContent', () => {
|
||||
]), { errorOnInvalidContent: true })
|
||||
}).to.throw('[tiptap error]: Invalid JSON content')
|
||||
})
|
||||
|
||||
it('if `errorOnInvalidContent` is true, will throw an error, when the JSON content does not follow the nesting rules of the schema', () => {
|
||||
const content = {
|
||||
type: 'paragraph',
|
||||
content: [{
|
||||
type: 'paragraph',
|
||||
content: [{
|
||||
type: 'text',
|
||||
text: 'Example Text',
|
||||
}],
|
||||
}],
|
||||
}
|
||||
|
||||
expect(() => {
|
||||
createNodeFromContent(content, getSchemaByResolvedExtensions([
|
||||
Document,
|
||||
Paragraph,
|
||||
Text,
|
||||
]), { errorOnInvalidContent: true })
|
||||
}).to.throw('[tiptap error]: Invalid JSON content')
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user