1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-29 09:59:48 +02:00

add ability to omit ranges in raw json, closes #152

This commit is contained in:
Ian Storm Taylor
2016-07-21 16:37:42 -07:00
parent 0dc348dec8
commit 57b5c9a8bd
3 changed files with 29 additions and 5 deletions

View File

@@ -34,10 +34,10 @@ function serializeNode(node) {
} }
} }
case 'text': { case 'text': {
return { const obj = {}
kind: node.kind, obj.kind = node.kind
ranges: serializeCharacters(node.characters) obj.ranges = serializeCharacters(node.characters)
} return obj
} }
case 'block': case 'block':
case 'inline': { case 'inline': {
@@ -128,6 +128,10 @@ function deserializeNode(object) {
}) })
} }
case 'text': { case 'text': {
if (object.ranges == null && object.text != null) {
object.ranges = [{ text: object.text }]
}
return Text.create({ return Text.create({
characters: object.ranges ? deserializeRanges(object.ranges) : '' characters: object.ranges ? deserializeRanges(object.ranges) : ''
}) })
@@ -145,7 +149,7 @@ function deserializeNode(object) {
* @return {List} characters * @return {List} characters
*/ */
function deserializeRanges(array) { function deserializeRanges(array = []) {
return array.reduce((characters, object) => { return array.reduce((characters, object) => {
const marks = object.marks || [] const marks = object.marks || []
const chars = object.text const chars = object.text

View File

@@ -0,0 +1,7 @@
nodes:
- kind: block
type: paragraph
nodes:
- kind: text
text: one

View File

@@ -0,0 +1,13 @@
nodes:
- type: paragraph
isVoid: false
data: {}
nodes:
- characters:
- text: o
marks: []
- text: n
marks: []
- text: e
marks: []