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:
@@ -34,10 +34,10 @@ function serializeNode(node) {
|
||||
}
|
||||
}
|
||||
case 'text': {
|
||||
return {
|
||||
kind: node.kind,
|
||||
ranges: serializeCharacters(node.characters)
|
||||
}
|
||||
const obj = {}
|
||||
obj.kind = node.kind
|
||||
obj.ranges = serializeCharacters(node.characters)
|
||||
return obj
|
||||
}
|
||||
case 'block':
|
||||
case 'inline': {
|
||||
@@ -128,6 +128,10 @@ function deserializeNode(object) {
|
||||
})
|
||||
}
|
||||
case 'text': {
|
||||
if (object.ranges == null && object.text != null) {
|
||||
object.ranges = [{ text: object.text }]
|
||||
}
|
||||
|
||||
return Text.create({
|
||||
characters: object.ranges ? deserializeRanges(object.ranges) : ''
|
||||
})
|
||||
@@ -145,7 +149,7 @@ function deserializeNode(object) {
|
||||
* @return {List} characters
|
||||
*/
|
||||
|
||||
function deserializeRanges(array) {
|
||||
function deserializeRanges(array = []) {
|
||||
return array.reduce((characters, object) => {
|
||||
const marks = object.marks || []
|
||||
const chars = object.text
|
||||
|
@@ -0,0 +1,7 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
text: one
|
@@ -0,0 +1,13 @@
|
||||
|
||||
nodes:
|
||||
- type: paragraph
|
||||
isVoid: false
|
||||
data: {}
|
||||
nodes:
|
||||
- characters:
|
||||
- text: o
|
||||
marks: []
|
||||
- text: n
|
||||
marks: []
|
||||
- text: e
|
||||
marks: []
|
Reference in New Issue
Block a user