1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-03-06 05:49:47 +01:00
Justin Weiss dce7e2c439 Allow null return values, which will skip serializing that node (#1699)
Sometimes, I have nodes that only make sense temporarily, so it
doesn't make sense to serialize them. Following the pattern in React,
explicitly returning `null` from a serialzation rule should result in
that node (and its children) not making it into the serialized document.
2018-03-22 14:54:35 -07:00

42 lines
816 B
JavaScript

/** @jsx h */
import React from 'react'
import h from '../helpers/h'
export const rules = [
{
serialize(obj, children) {
if (obj.object == 'block' && obj.type == 'paragraph') {
return React.createElement('p', {}, children)
}
if (obj.object == 'inline' && obj.type == 'link') {
return React.createElement('a', {}, children)
}
if (obj.object == 'inline' && obj.type == 'comment') {
return null
}
if (obj.object == 'block' && obj.type == 'quote') {
return null
}
},
},
]
export const input = (
<value>
<document>
<paragraph>
Something <comment>skipped</comment> Here
</paragraph>
<quote>Skipped</quote>
</document>
</value>
)
export const output = `
<p>Something Here</p>
`.trim()