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

Fix word counting (#2247)

This commit is contained in:
Jinxuan Zhu
2018-10-10 17:00:45 -04:00
committed by Ian Storm Taylor
parent 10bf13804f
commit 3c1e3a1574

View File

@@ -12,12 +12,13 @@ export default function WordCount(options) {
return {
renderEditor(props, next) {
const children = next()
const wordCount = props.value.document
.getBlocks()
.reduce((memo, b) => memo + b.text.trim().split(/\s+/).length, 0)
return (
<div>
<div>{children}</div>
<WordCounter>
Word Count: {props.value.document.text.split(' ').length}
</WordCounter>
<WordCounter>Word Count: {wordCount}</WordCounter>
</div>
)
},