1
0
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:
Julien Poissonnier 2017-12-29 19:47:06 +01:00 committed by Ian Storm Taylor
parent 7dc93dced9
commit 0e33c8bb35
4 changed files with 35 additions and 6 deletions

View File

@ -287,13 +287,11 @@ 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) {
if (!rule.marks.some(def => def.type === mark.type)) {
return this.fail(NODE_MARK_INVALID, { ...ctx, mark })
}
}
}
}
if (rule.text != null) {
const { text } = node

View File

@ -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))

View File

@ -5,7 +5,7 @@ import h from '../../helpers/h'
export const schema = {
blocks: {
paragraph: {
marks: ['bold'],
marks: [{ type: 'bold' }, { type: 'underline' }],
}
}
}

View 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>
)