diff --git a/packages/slate-plain-serializer/src/index.js b/packages/slate-plain-serializer/src/index.js
index 7e8decf1b..817273139 100644
--- a/packages/slate-plain-serializer/src/index.js
+++ b/packages/slate-plain-serializer/src/index.js
@@ -13,7 +13,12 @@ import { Set } from 'immutable'
*/
function deserialize(string, options = {}) {
- let { defaultBlock = 'line', defaultMarks = [], toJSON = false } = options
+ let {
+ defaultBlock = 'line',
+ defaultMarks = [],
+ delimiter = '\n',
+ toJSON = false,
+ } = options
if (Set.isSet(defaultMarks)) {
defaultMarks = defaultMarks.toArray()
@@ -27,7 +32,7 @@ function deserialize(string, options = {}) {
document: {
object: 'document',
data: {},
- nodes: string.split('\n').map(line => {
+ nodes: string.split(delimiter).map(line => {
return {
...defaultBlock,
object: 'block',
@@ -60,8 +65,8 @@ function deserialize(string, options = {}) {
* @return {String}
*/
-function serialize(value) {
- return serializeNode(value.document)
+function serialize(value, options = {}) {
+ return serializeNode(value.document, options)
}
/**
@@ -71,12 +76,14 @@ function serialize(value) {
* @return {String}
*/
-function serializeNode(node) {
+function serializeNode(node, options = {}) {
+ const { delimiter = '\n' } = options
+
if (
node.object == 'document' ||
(node.object == 'block' && Block.isBlockList(node.nodes))
) {
- return node.nodes.map(serializeNode).join('\n')
+ return node.nodes.map(serializeNode).join(delimiter)
} else {
return node.text
}
diff --git a/packages/slate-plain-serializer/test/deserialize/custom-delimiter.js b/packages/slate-plain-serializer/test/deserialize/custom-delimiter.js
new file mode 100644
index 000000000..00c5849a5
--- /dev/null
+++ b/packages/slate-plain-serializer/test/deserialize/custom-delimiter.js
@@ -0,0 +1,24 @@
+/** @jsx h */
+
+import h from '../helpers/h'
+
+export const input = `
+one
+same paragraph
+
+two
+`.trim()
+
+export const output = (
+
+
+ one{'\n'}same paragraph
+ two
+
+
+)
+
+export const options = {
+ defaultBlock: 'paragraph',
+ delimiter: '\n\n',
+}
diff --git a/packages/slate-plain-serializer/test/serialize/custom-delimiter.js b/packages/slate-plain-serializer/test/serialize/custom-delimiter.js
new file mode 100644
index 000000000..2ba8e021f
--- /dev/null
+++ b/packages/slate-plain-serializer/test/serialize/custom-delimiter.js
@@ -0,0 +1,26 @@
+/** @jsx h */
+
+import h from '../helpers/h'
+
+export const input = (
+
+
+ one{'\n'}same paragraph
+ two
+ three
+
+
+)
+
+export const output = `
+one
+same paragraph
+
+two
+
+three
+`.trim()
+
+export const options = {
+ delimiter: '\n\n',
+}