mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
Merge pull request #4877 from harryhope/master
Ignore non-words in word counter
This commit is contained in:
commit
8b0505070d
@ -1,11 +1,13 @@
|
||||
// jscs: disable
|
||||
function wordCount(s) {
|
||||
s = s.replace(/(^\s*)|(\s*$)/gi, ''); // exclude start and end white-space
|
||||
s = s.replace(/[ ]{2,}/gi, ' '); // 2 or more space to 1
|
||||
s = s.replace(/\n /gi, '\n'); // exclude newline with a start spacing
|
||||
s = s.replace(/\n+/gi, '\n');
|
||||
s = s.replace(/<(.|\n)*?>/g, ' '); // strip tags
|
||||
s = s.replace(/[^\w\s]/g, ''); // ignore non-alphanumeric letters
|
||||
s = s.replace(/(^\s*)|(\s*$)/gi, ''); // exclude starting and ending white-space
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user