diff --git a/src/wp-admin/js/word-count.js b/src/wp-admin/js/word-count.js
index c1902c39bc..40c2934b9e 100644
--- a/src/wp-admin/js/word-count.js
+++ b/src/wp-admin/js/word-count.js
@@ -17,6 +17,7 @@
removeRegExp: /[0-9.(),;:!?%#$¿'"_+=\\\/-]+/g,
wordsRegExp: /\S\s+/g,
charactersRegExp: /\S/g,
+ allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g,
l10n: window.wordCountL10n || {}
};
@@ -26,9 +27,9 @@
type = type || this.settings.l10n.type || 'words';
if ( text ) {
- text = ' ' + text + ' ';
+ text = text + '\n';
- text = text.replace( this.settings.HTMLRegExp, ' ' );
+ text = text.replace( this.settings.HTMLRegExp, '\n' );
text = text.replace( this.settings.spaceRegExp, ' ' );
text = text.replace( this.settings.removeRegExp, '' );
diff --git a/tests/qunit/wp-admin/js/word-count.js b/tests/qunit/wp-admin/js/word-count.js
index 4d10e85200..5d3664f583 100644
--- a/tests/qunit/wp-admin/js/word-count.js
+++ b/tests/qunit/wp-admin/js/word-count.js
@@ -1,47 +1,47 @@
-( function( QUnit ) {
- var wordCounter = new window.wp.utils.WordCounter();
-
+( function( QUnit, wordCounter ) {
QUnit.module( 'word-count' );
QUnit.test( 'All.', function( assert ) {
- var tests = [
+ _.each( [
{
message: 'Basic test.',
string: 'one two three',
- wordCount: 3,
- charCount: 11
+ words: 3,
+ characters: 11,
+ all: 13
},
{
message: 'HTML tags.',
string: 'one two
three',
- wordCount: 3,
- charCount: 11
+ words: 3,
+ characters: 11,
+ all: 12
},
{
message: 'Line breaks.',
string: 'one\ntwo\nthree',
- wordCount: 3,
- charCount: 11
+ words: 3,
+ characters: 11,
+ all: 11
},
{
message: 'Encoded spaces.',
string: 'one two three',
- wordCount: 3,
- charCount: 11
+ words: 3,
+ characters: 11,
+ all: 13
},
{
message: 'Punctuation.',
string: 'It\'s two three... 4?',
- wordCount: 3,
- charCount: 11
+ words: 3,
+ characters: 11,
+ all: 14
}
- ];
-
- var i = tests.length;
-
- while ( i-- ) {
- assert.equal( wordCounter.count( tests[ i ].string ), tests[ i ].wordCount, tests[ i ].message + ' (words)' );
- assert.equal( wordCounter.count( tests[ i ].string, 'characters' ), tests[ i ].charCount, tests[ i ].message + ' (characters)' );
- }
+ ], function( test ) {
+ _.each( [ 'words', 'characters', 'all' ], function( type ) {
+ assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
+ } );
+ } );
} );
-} )( window.QUnit );
+} )( window.QUnit, new window.wp.utils.WordCounter() );