mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-25 16:20:49 +02:00
Fix word counting (#2247)
This commit is contained in:
committed by
Ian Storm Taylor
parent
10bf13804f
commit
3c1e3a1574
@@ -12,12 +12,13 @@ export default function WordCount(options) {
|
|||||||
return {
|
return {
|
||||||
renderEditor(props, next) {
|
renderEditor(props, next) {
|
||||||
const children = next()
|
const children = next()
|
||||||
|
const wordCount = props.value.document
|
||||||
|
.getBlocks()
|
||||||
|
.reduce((memo, b) => memo + b.text.trim().split(/\s+/).length, 0)
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div>{children}</div>
|
<div>{children}</div>
|
||||||
<WordCounter>
|
<WordCounter>Word Count: {wordCount}</WordCounter>
|
||||||
Word Count: {props.value.document.text.split(' ').length}
|
|
||||||
</WordCounter>
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user