mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-02-13 11:44:55 +01:00
Fix schema marks validation (#1483)
This commit is contained in:
parent
7dc93dced9
commit
0e33c8bb35
@ -287,10 +287,8 @@ class Schema extends Record(DEFAULTS) {
|
||||
const marks = node.getMarks().toArray()
|
||||
|
||||
for (const mark of marks) {
|
||||
for (const def of rule.marks) {
|
||||
if (def.type != mark.type) {
|
||||
return this.fail(NODE_MARK_INVALID, { ...ctx, mark })
|
||||
}
|
||||
if (!rule.marks.some(def => def.type === mark.type)) {
|
||||
return this.fail(NODE_MARK_INVALID, { ...ctx, mark })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import h from '../../helpers/h'
|
||||
export const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
marks: ['bold'],
|
||||
marks: [{ type: 'bold' }],
|
||||
normalize: (change, reason, { node }) => {
|
||||
if (reason == 'node_mark_invalid') {
|
||||
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
||||
|
@ -5,7 +5,7 @@ import h from '../../helpers/h'
|
||||
export const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
marks: ['bold'],
|
||||
marks: [{ type: 'bold' }, { type: 'underline' }],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
31
packages/slate/test/schema/custom/node-mark-valid-default.js
Normal file
31
packages/slate/test/schema/custom/node-mark-valid-default.js
Normal file
@ -0,0 +1,31 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../../helpers/h'
|
||||
|
||||
export const schema = {
|
||||
blocks: {
|
||||
paragraph: {
|
||||
marks: [{ type: 'bold' }, { type: 'underline' }],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const input = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
one <b>two</b> three
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
||||
|
||||
export const output = (
|
||||
<value>
|
||||
<document>
|
||||
<paragraph>
|
||||
one <b>two</b> three
|
||||
</paragraph>
|
||||
</document>
|
||||
</value>
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user