1
0
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:
Ian Storm Taylor
2016-07-18 16:18:55 -07:00
parent a3fedffde7
commit 54587c3318
5 changed files with 44 additions and 1 deletions

View File

@@ -16,6 +16,7 @@ p {
pre {
padding: 10px;
background-color: #eee;
white-space: pre-wrap;
}
img {

View File

@@ -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 })

View 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
}

View File

@@ -0,0 +1,8 @@
nodes:
- kind: block
type: default
nodes:
- kind: text
ranges:
- text: one

View 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>