1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 02:49:56 +02:00

add support for skipping elements in html serializer, closes #821

This commit is contained in:
Ian Storm Taylor
2017-05-17 09:14:33 -07:00
parent e363f88b71
commit c260725e65
5 changed files with 50 additions and 6 deletions

View File

@@ -4,6 +4,17 @@ This document maintains a list of changes to Slate with each new version. Until
---
### `0.20.0` — May 17, 2017
###### BREAKING CHANGES
- **Returning `null` from the `Html` serializer skips the element.** Previously, `null` and `undefined` had the same behavior of skipping the rule and trying the rest of the rules. Now if you explicitly return `null` it will skip the element itself.
---
### `0.19.0` — March 3, 2017
###### BREAKING CHANGES

View File

@@ -159,11 +159,6 @@ class Html {
case 'object':
nodes.push(node)
break
case 'null':
case 'undefined':
return
default:
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`)
}
})
@@ -196,8 +191,16 @@ class Html {
for (const rule of this.rules) {
if (!rule.deserialize) continue
const ret = rule.deserialize(element, next)
if (!ret) continue
if (ret === undefined) continue
if (ret === null) break
const type = typeOf(ret)
if (type != 'array' && type != 'object') {
throw new Error(`A rule returned an invalid deserialized representation: "${node}".`)
}
node = ret.kind == 'mark' ? this.deserializeMark(ret) : ret
break
}

View File

@@ -0,0 +1,20 @@
export default {
rules: [
{
deserialize(el, next) {
if (el.tagName == 'div') {
return null
}
}
},
{
deserialize(el, next) {
return {
kind: 'block',
type: 'paragraph',
}
}
},
]
}

View File

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

View File

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