1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 06:53:25 +02:00

Allow Data to be passed to Marks when using HTML Deserializer (#986)

* making it possible to pass in data to marks on deserialize

* adding a test to make sure this doesn't happen again
This commit is contained in:
Ryan Yurkanin
2017-08-15 13:26:49 -04:00
committed by Ian Storm Taylor
parent 18f41e72ce
commit ff57cd697f
4 changed files with 51 additions and 2 deletions

View File

@@ -246,7 +246,7 @@ class Html {
*/ */
deserializeMark = (mark) => { deserializeMark = (mark) => {
const { type, value } = mark const { type, data } = mark
const applyMark = (node) => { const applyMark = (node) => {
if (node.kind == 'mark') { if (node.kind == 'mark') {
@@ -257,7 +257,7 @@ class Html {
if (!node.ranges) node.ranges = [{ text: node.text }] if (!node.ranges) node.ranges = [{ text: node.text }]
node.ranges = node.ranges.map((range) => { node.ranges = node.ranges.map((range) => {
range.marks = range.marks || [] range.marks = range.marks || []
range.marks.push({ type, value }) range.marks.push({ type, data })
return range return range
}) })
} }

View File

@@ -0,0 +1,28 @@
export default {
rules: [
{
deserialize(el, next) {
switch (el.tagName) {
case 'p': {
return {
kind: 'block',
type: 'paragraph',
nodes: next(el.childNodes)
}
}
case 'mark': {
return {
kind: 'mark',
type: 'highlight',
data: {
backgroundColor: 'green',
},
nodes: next(el.childNodes)
}
}
}
}
}
]
}

View File

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

View File

@@ -0,0 +1,20 @@
data: {}
nodes:
- type: paragraph
isVoid: false
data: {}
nodes:
- characters:
- text: o
marks:
- type: highlight
data: { backgroundColor: "green" }
- text: n
marks:
- type: highlight
data: { backgroundColor: "green" }
- text: e
marks:
- type: highlight
data: { backgroundColor: "green" }