mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 11:42:53 +02:00
do not throw too early while looking for a rule with which to serialize (#205)
This commit is contained in:
committed by
Ian Storm Taylor
parent
d2647cde71
commit
9ab6267271
@@ -245,8 +245,8 @@ class Html {
|
|||||||
if (!rule.serialize) continue
|
if (!rule.serialize) continue
|
||||||
const ret = rule.serialize(node, children)
|
const ret = rule.serialize(node, children)
|
||||||
if (ret) return addKey(ret)
|
if (ret) return addKey(ret)
|
||||||
throw new Error(`No serializer defined for node of type "${node.type}".`)
|
|
||||||
}
|
}
|
||||||
|
throw new Error(`No serializer defined for node of type "${node.type}".`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -265,8 +265,8 @@ class Html {
|
|||||||
if (!rule.serialize) continue
|
if (!rule.serialize) continue
|
||||||
const ret = rule.serialize(mark, children)
|
const ret = rule.serialize(mark, children)
|
||||||
if (ret) return addKey(ret)
|
if (ret) return addKey(ret)
|
||||||
throw new Error(`No serializer defined for mark of type "${mark.type}".`)
|
|
||||||
}
|
}
|
||||||
|
throw new Error(`No serializer defined for mark of type "${mark.type}".`)
|
||||||
}, text)
|
}, text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
rules: [
|
||||||
|
// the first one has no serialize()
|
||||||
|
{},
|
||||||
|
// the second has a serialize() that does not return anything
|
||||||
|
{
|
||||||
|
serialize(obj, children) {}
|
||||||
|
},
|
||||||
|
// then the real one
|
||||||
|
{
|
||||||
|
serialize(obj, children) {
|
||||||
|
if (obj.kind == 'block' && obj.type == 'paragraph') {
|
||||||
|
return <p>{children}</p>
|
||||||
|
}
|
||||||
|
if (obj.kind == 'inline' && obj.type == 'link') {
|
||||||
|
return <a>{children}</a>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import { Block, Character, Document, Inline, Mark, State, Text } from '../../../../../..'
|
||||||
|
|
||||||
|
export default State.create({
|
||||||
|
document: Document.create({
|
||||||
|
nodes: Block.createList([
|
||||||
|
{
|
||||||
|
type: 'paragraph',
|
||||||
|
nodes: Inline.createList([
|
||||||
|
{
|
||||||
|
type: 'link',
|
||||||
|
nodes: Text.createList([
|
||||||
|
{
|
||||||
|
characters: Character.createList([
|
||||||
|
{ text: 't' },
|
||||||
|
{ text: 'w' },
|
||||||
|
{ text: 'o' }
|
||||||
|
])
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
])
|
||||||
|
}
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
@@ -0,0 +1 @@
|
|||||||
|
<p><a>two</a></p>
|
Reference in New Issue
Block a user