mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-09-02 03:32:36 +02:00
add support for skipping elements in html serializer, closes #821
This commit is contained in:
11
History.md
11
History.md
@@ -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
|
### `0.19.0` — March 3, 2017
|
||||||
|
|
||||||
###### BREAKING CHANGES
|
###### BREAKING CHANGES
|
||||||
|
@@ -159,11 +159,6 @@ class Html {
|
|||||||
case 'object':
|
case 'object':
|
||||||
nodes.push(node)
|
nodes.push(node)
|
||||||
break
|
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) {
|
for (const rule of this.rules) {
|
||||||
if (!rule.deserialize) continue
|
if (!rule.deserialize) continue
|
||||||
|
|
||||||
const ret = rule.deserialize(element, next)
|
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
|
node = ret.kind == 'mark' ? this.deserializeMark(ret) : ret
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
export default {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
deserialize(el, next) {
|
||||||
|
if (el.tagName == 'div') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deserialize(el, next) {
|
||||||
|
return {
|
||||||
|
kind: 'block',
|
||||||
|
type: 'paragraph',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
@@ -0,0 +1,2 @@
|
|||||||
|
<p></p>
|
||||||
|
<div></div>
|
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
data: {}
|
||||||
|
nodes:
|
||||||
|
- type: paragraph
|
||||||
|
isVoid: false
|
||||||
|
data: {}
|
||||||
|
nodes:
|
||||||
|
- characters: []
|
Reference in New Issue
Block a user