mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-21 13:51:59 +02:00
Allow setting a defaultBlockType as object for HTML serializer (#595)
* Allow setting a defaultBlockType as object for HTML serializer * Add test for html deserializer default block as object * Code enhancement/compacting
This commit is contained in:
parent
0430efcdc8
commit
add174ef37
src/serializers
test/serializers/fixtures/html/deserialize/default-block
@ -70,6 +70,7 @@ class Html {
|
||||
* @param {Object} options
|
||||
* @property {Array} rules
|
||||
* @property {String} defaultBlockType
|
||||
* @property {String|Object} defaultBlockType
|
||||
*/
|
||||
|
||||
constructor(options = {}) {
|
||||
@ -108,11 +109,10 @@ class Html {
|
||||
return memo
|
||||
}
|
||||
|
||||
const block = {
|
||||
kind: 'block',
|
||||
type: this.defaultBlockType,
|
||||
nodes: [node]
|
||||
}
|
||||
const commonProps = {kind: 'block', nodes: [node]}
|
||||
const block = this.defaultBlockType.typeof === 'string'
|
||||
? {type: this.defaultBlockType, ...commonProps}
|
||||
: {...commonProps, ...this.defaultBlockType}
|
||||
|
||||
memo.push(block)
|
||||
return memo
|
||||
|
@ -0,0 +1,24 @@
|
||||
|
||||
export default {
|
||||
rules: [
|
||||
{
|
||||
deserialize(el, next) {
|
||||
switch (el.tagName) {
|
||||
case 'p': {
|
||||
return {
|
||||
kind: 'block',
|
||||
type: 'paragraph',
|
||||
nodes: next(el.children)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
defaultBlockType: {
|
||||
type: 'contentBlock',
|
||||
data: {
|
||||
style: 'default'
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
<p>one</p>
|
||||
<div>two</div>
|
@ -0,0 +1,25 @@
|
||||
data: {}
|
||||
nodes:
|
||||
- type: paragraph
|
||||
isVoid: false
|
||||
data: {}
|
||||
nodes:
|
||||
- characters:
|
||||
- text: o
|
||||
marks: []
|
||||
- text: n
|
||||
marks: []
|
||||
- text: e
|
||||
marks: []
|
||||
- type: contentBlock
|
||||
isVoid: false
|
||||
data: {style: default}
|
||||
nodes:
|
||||
- characters:
|
||||
- text: t
|
||||
marks: []
|
||||
- text: w
|
||||
marks: []
|
||||
- text: o
|
||||
marks: []
|
||||
|
Loading…
x
Reference in New Issue
Block a user