mirror of
https://github.com/ueberdosis/tiptap.git
synced 2025-06-08 01:53:04 +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 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) {
|
} catch (error) {
|
||||||
if (options.errorOnInvalidContent) {
|
if (options.errorOnInvalidContent) {
|
||||||
throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error })
|
throw new Error('[tiptap error]: Invalid JSON content', { cause: error as Error })
|
||||||
|
@ -242,4 +242,25 @@ describe('createNodeFromContent', () => {
|
|||||||
]), { errorOnInvalidContent: true })
|
]), { errorOnInvalidContent: true })
|
||||||
}).to.throw('[tiptap error]: Invalid JSON content')
|
}).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