mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-22 15:02:51 +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:
committed by
Ian Storm Taylor
parent
18f41e72ce
commit
ff57cd697f
@@ -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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@@ -0,0 +1 @@
|
|||||||
|
<p><mark>one</mark></p>
|
@@ -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" }
|
Reference in New Issue
Block a user