mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 15:32:59 +02:00
Fix schema marks validation (#1483)
This commit is contained in:
committed by
Ian Storm Taylor
parent
7dc93dced9
commit
0e33c8bb35
@@ -287,10 +287,8 @@ class Schema extends Record(DEFAULTS) {
|
|||||||
const marks = node.getMarks().toArray()
|
const marks = node.getMarks().toArray()
|
||||||
|
|
||||||
for (const mark of marks) {
|
for (const mark of marks) {
|
||||||
for (const def of rule.marks) {
|
if (!rule.marks.some(def => def.type === mark.type)) {
|
||||||
if (def.type != mark.type) {
|
return this.fail(NODE_MARK_INVALID, { ...ctx, mark })
|
||||||
return this.fail(NODE_MARK_INVALID, { ...ctx, mark })
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import h from '../../helpers/h'
|
|||||||
export const schema = {
|
export const schema = {
|
||||||
blocks: {
|
blocks: {
|
||||||
paragraph: {
|
paragraph: {
|
||||||
marks: ['bold'],
|
marks: [{ type: 'bold' }],
|
||||||
normalize: (change, reason, { node }) => {
|
normalize: (change, reason, { node }) => {
|
||||||
if (reason == 'node_mark_invalid') {
|
if (reason == 'node_mark_invalid') {
|
||||||
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
node.nodes.forEach(n => change.removeNodeByKey(n.key))
|
||||||
|
@@ -5,7 +5,7 @@ import h from '../../helpers/h'
|
|||||||
export const schema = {
|
export const schema = {
|
||||||
blocks: {
|
blocks: {
|
||||||
paragraph: {
|
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>
|
||||||
|
)
|
Reference in New Issue
Block a user