mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-21 22:45:18 +02:00
add decorator rendering test
This commit is contained in:
@@ -16,6 +16,7 @@ p {
|
||||
pre {
|
||||
padding: 10px;
|
||||
background-color: #eee;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
img {
|
||||
|
@@ -857,7 +857,10 @@ const Node = {
|
||||
let ret = node
|
||||
if (ret.kind != 'text') ret = ret.mapDescendants(iterator)
|
||||
ret = iterator(ret, i, this.nodes)
|
||||
if (ret != node) nodes = nodes.set(ret.key, ret)
|
||||
if (ret == node) return
|
||||
|
||||
const index = nodes.indexOf(node)
|
||||
nodes = nodes.set(index, ret)
|
||||
})
|
||||
|
||||
return this.merge({ nodes })
|
||||
|
21
test/rendering/fixtures/custom-decorator/index.js
Normal file
21
test/rendering/fixtures/custom-decorator/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
|
||||
import React from 'react'
|
||||
import { Mark } from '../../../..'
|
||||
|
||||
const BOLD = {
|
||||
fontWeight: 'bold'
|
||||
}
|
||||
|
||||
export function renderMark(mark) {
|
||||
if (mark.type == 'bold') return BOLD
|
||||
}
|
||||
|
||||
export function renderDecorations(text) {
|
||||
let { characters } = text
|
||||
let second = characters.get(1)
|
||||
let mark = Mark.create({ type: 'bold' })
|
||||
let marks = second.marks.add(mark)
|
||||
second = second.merge({ marks })
|
||||
characters = characters.set(1, second)
|
||||
return characters
|
||||
}
|
8
test/rendering/fixtures/custom-decorator/input.yaml
Normal file
8
test/rendering/fixtures/custom-decorator/input.yaml
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: default
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: one
|
10
test/rendering/fixtures/custom-decorator/output.html
Normal file
10
test/rendering/fixtures/custom-decorator/output.html
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
<div contenteditable="true">
|
||||
<div>
|
||||
<span>
|
||||
<span>o</span>
|
||||
<span style="font-weight:bold;">n</span>
|
||||
<span>e</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
Reference in New Issue
Block a user