diff --git a/lib/serializers/raw.js b/lib/serializers/raw.js index 0c5e2ca3d..254f5a5f6 100644 --- a/lib/serializers/raw.js +++ b/lib/serializers/raw.js @@ -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 diff --git a/test/serializers/fixtures/raw/deserialize/text-without-range/input.yaml b/test/serializers/fixtures/raw/deserialize/text-without-range/input.yaml new file mode 100644 index 000000000..3c2724d28 --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize/text-without-range/input.yaml @@ -0,0 +1,7 @@ + +nodes: + - kind: block + type: paragraph + nodes: + - kind: text + text: one diff --git a/test/serializers/fixtures/raw/deserialize/text-without-range/output.yaml b/test/serializers/fixtures/raw/deserialize/text-without-range/output.yaml new file mode 100644 index 000000000..4c208207b --- /dev/null +++ b/test/serializers/fixtures/raw/deserialize/text-without-range/output.yaml @@ -0,0 +1,13 @@ + +nodes: + - type: paragraph + isVoid: false + data: {} + nodes: + - characters: + - text: o + marks: [] + - text: n + marks: [] + - text: e + marks: []