mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-27 14:59:27 +08:00
This commit is contained in:
parent
a22767e9e1
commit
f805333f63
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