mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 22:45:18 +02:00
Allow HTMLSerializer to deserialize an empty doc (#915)
* Allow HTML serializer to deserialize an empty document This specially handles the case where the HTML is empty. Test by running: ``` const html = new HTML() html.deserialize('') ``` Closes #539 * Use defaultBlockType in HTML serializer * Add test case for deserialising empty string * Use fixtures
This commit is contained in:
committed by
Ian Storm Taylor
parent
a1d4de3b20
commit
30f1a9ef1d
@@ -98,6 +98,11 @@ class Html {
|
||||
const children = $.children().toArray()
|
||||
let nodes = this.deserializeElements(children)
|
||||
|
||||
const { defaultBlockType } = this
|
||||
const defaults = typeof defaultBlockType == 'string'
|
||||
? { type: defaultBlockType }
|
||||
: defaultBlockType
|
||||
|
||||
// HACK: ensure for now that all top-level inline are wrapped into a block.
|
||||
nodes = nodes.reduce((memo, node, i, original) => {
|
||||
if (node.kind == 'block') {
|
||||
@@ -111,11 +116,6 @@ class Html {
|
||||
return memo
|
||||
}
|
||||
|
||||
const { defaultBlockType } = this
|
||||
const defaults = typeof defaultBlockType == 'string'
|
||||
? { type: defaultBlockType }
|
||||
: defaultBlockType
|
||||
|
||||
const block = {
|
||||
kind: 'block',
|
||||
nodes: [node],
|
||||
@@ -126,6 +126,14 @@ class Html {
|
||||
return memo
|
||||
}, [])
|
||||
|
||||
if (nodes.length === 0) {
|
||||
nodes = [{
|
||||
kind: 'block',
|
||||
nodes: [],
|
||||
...defaults
|
||||
}]
|
||||
}
|
||||
|
||||
const raw = {
|
||||
kind: 'state',
|
||||
document: {
|
||||
|
@@ -0,0 +1 @@
|
||||
export default {}
|
@@ -0,0 +1,7 @@
|
||||
data: {}
|
||||
nodes:
|
||||
- type: paragraph
|
||||
isVoid: false
|
||||
data: {}
|
||||
nodes:
|
||||
- characters: []
|
Reference in New Issue
Block a user