diff --git a/lib/wordcount-view.coffee b/lib/wordcount-view.coffee index 94a94b6..cd1d673 100644 --- a/lib/wordcount-view.coffee +++ b/lib/wordcount-view.coffee @@ -12,9 +12,12 @@ class WordcountView @element.appendChild(@divWords) + @wordregex = require('word-regex')() + update_count: (editor) -> texts = @getTexts editor + scope = editor.getGrammar().scopeName wordCount = charCount = 0 for text in texts text = @stripText text, editor @@ -82,10 +85,13 @@ class WordcountView for pattern in blockquotePatterns text = text?.replace pattern, '' + # Reduce links to text + text = text?.replace /(?:__|[*#])|\[(.*?)\]\(.*?\)/gm, '$1' + text count: (text) -> - words = text?.match(/\S+/g)?.length + words = text?.match(@wordregex)?.length text = text?.replace '\n', '' text = text?.replace '\r', '' chars = text?.length diff --git a/package.json b/package.json index 9e98685..26a9088 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ "atom": ">=0.180.0" }, "dependencies": { - "lodash": "^3.10.1" + "lodash": "^3.10.1", + "word-regex": "^0.1.2" }, "consumedServices": { "status-bar": {