mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
ignore non-words in word counter
This commit is contained in:
parent
950f9c29b3
commit
6361976c39
1 changed files with 7 additions and 5 deletions
|
@ -1,11 +1,13 @@
|
||||||
// jscs: disable
|
// jscs: disable
|
||||||
function wordCount(s) {
|
function wordCount(s) {
|
||||||
s = s.replace(/(^\s*)|(\s*$)/gi, ''); // exclude start and end white-space
|
s = s.replace(/<(.|\n)*?>/g, ' '); // strip tags
|
||||||
s = s.replace(/[ ]{2,}/gi, ' '); // 2 or more space to 1
|
s = s.replace(/[^\w\s]/g, ''); // ignore non-alphanumeric letters
|
||||||
s = s.replace(/\n /gi, '\n'); // exclude newline with a start spacing
|
s = s.replace(/(^\s*)|(\s*$)/gi, ''); // exclude starting and ending white-space
|
||||||
s = s.replace(/\n+/gi, '\n');
|
s = s.replace(/\n /gi, ' '); // convert newlines to spaces
|
||||||
|
s = s.replace(/\n+/gi, ' ');
|
||||||
|
s = s.replace(/[ ]{2,}/gi, ' '); // convert 2 or more spaces to 1
|
||||||
|
|
||||||
return s.split(/ |\n/).length;
|
return s.split(' ').length;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default wordCount;
|
export default wordCount;
|
||||||
|
|
Loading…
Add table
Reference in a new issue