From 6e2765da701a8290784bc66e8e2f1e70656db397 Mon Sep 17 00:00:00 2001 From: Harry Hope Date: Sun, 1 Feb 2015 01:22:20 -0500 Subject: [PATCH] ignore non-words in word counter --- ghost/admin/utils/word-count.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ghost/admin/utils/word-count.js b/ghost/admin/utils/word-count.js index 81b6577121..164a141f49 100644 --- a/ghost/admin/utils/word-count.js +++ b/ghost/admin/utils/word-count.js @@ -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;