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:
committed by
Ian Storm Taylor
parent
10bf13804f
commit
3c1e3a1574
@@ -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>
|
||||
)
|
||||
},
|
||||
|
Reference in New Issue
Block a user