From 2687def4002551c76ee15410a5deef95da740c4d Mon Sep 17 00:00:00 2001 From: Artyom Fedenko Date: Sat, 2 May 2015 22:56:33 +0300 Subject: [PATCH] Added support for all letters in word-count (not only ASCII) and added xregexp bower module to a project --- ghost/admin/Brocfile.js | 1 + ghost/admin/app/utils/word-count.js | 7 ++++++- ghost/admin/bower.json | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ghost/admin/Brocfile.js b/ghost/admin/Brocfile.js index 64d918e5df..4d89258a04 100644 --- a/ghost/admin/Brocfile.js +++ b/ghost/admin/Brocfile.js @@ -59,5 +59,6 @@ app.import('bower_components/codemirror/mode/htmlmixed/htmlmixed.js'); app.import('bower_components/codemirror/mode/xml/xml.js'); app.import('bower_components/codemirror/mode/css/css.js'); app.import('bower_components/codemirror/mode/javascript/javascript.js'); +app.import('bower_components/xregexp/xregexp-all.js'); module.exports = app.toTree(); diff --git a/ghost/admin/app/utils/word-count.js b/ghost/admin/app/utils/word-count.js index 164a141f49..4f1f60d15a 100644 --- a/ghost/admin/app/utils/word-count.js +++ b/ghost/admin/app/utils/word-count.js @@ -1,7 +1,12 @@ // jscs: disable +/* global XRegExp */ + function wordCount(s) { + + var nonANumLetters = new XRegExp("[^\\s\\d\\p{L}]", "g"); // all non-alphanumeric letters regexp + s = s.replace(/<(.|\n)*?>/g, ' '); // strip tags - s = s.replace(/[^\w\s]/g, ''); // ignore non-alphanumeric letters + s = s.replace(nonANumLetters, ''); // 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, ' '); diff --git a/ghost/admin/bower.json b/ghost/admin/bower.json index eb750fe214..7bf3507410 100644 --- a/ghost/admin/bower.json +++ b/ghost/admin/bower.json @@ -25,7 +25,8 @@ "nprogress": "0.1.6", "rangyinputs": "1.2.0", "showdown-ghost": "0.3.6", - "validator-js": "3.39.0" + "validator-js": "3.39.0", + "xregexp": "2.0.0" }, "devDependencies": {