1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

fix html serializer for cases without children

This commit is contained in:
Ian Storm Taylor
2016-08-11 12:28:41 -07:00
parent 76211ebcd0
commit 6ab2d963cd
12 changed files with 93 additions and 4 deletions

View File

@@ -44,8 +44,8 @@
"no-array-constructor": "error",
"no-class-assign": "error",
"no-const-assign": "error",
"no-console": "warn",
"no-debugger": "warn",
"no-console": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-keys": "error",

View File

@@ -480,7 +480,7 @@ const Raw = {
*/
untersifyBlock(object) {
if (object.isVoid) {
if (object.isVoid || !object.nodes || !object.nodes.length) {
return {
data: object.data,
kind: object.kind,
@@ -506,7 +506,7 @@ const Raw = {
*/
untersifyInline(object) {
if (object.isVoid) {
if (object.isVoid || !object.nodes || !object.nodes.length) {
return {
data: object.data,
kind: object.kind,

View File

@@ -0,0 +1,25 @@
export default {
rules: [
{
deserialize(el, next) {
switch (el.tagName) {
case 'p': {
return {
kind: 'block',
type: 'paragraph',
nodes: next(el.children)
}
}
case 'a': {
return {
kind: 'inline',
type: 'link',
nodes: next(el.children)
}
}
}
}
}
]
}

View File

@@ -0,0 +1 @@
<p></p>

View File

@@ -0,0 +1,7 @@
nodes:
- type: paragraph
isVoid: false
data: {}
nodes:
- characters: []

View File

@@ -0,0 +1,25 @@
export default {
rules: [
{
deserialize(el, next) {
switch (el.tagName) {
case 'p': {
return {
kind: 'block',
type: 'paragraph',
nodes: next(el.children)
}
}
case 'a': {
return {
kind: 'inline',
type: 'link',
nodes: next(el.children)
}
}
}
}
}
]
}

View File

@@ -0,0 +1 @@
<p><a></a></p>

View File

@@ -0,0 +1,7 @@
nodes:
- type: paragraph
isVoid: false
data: {}
nodes:
- characters: []

View File

@@ -0,0 +1,5 @@
nodes:
- kind: block
type: paragraph
nodes: []

View File

@@ -0,0 +1,7 @@
nodes:
- type: paragraph
isVoid: false
data: {}
nodes:
- characters: []

View File

@@ -0,0 +1,4 @@
nodes:
- kind: block
type: paragraph

View File

@@ -0,0 +1,7 @@
nodes:
- type: paragraph
isVoid: false
data: {}
nodes:
- characters: []