Editor: word count: add `all` type
This type will count all characters including spaces. See #30966. git-svn-id: https://develop.svn.wordpress.org/trunk@33290 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
302a039de1
commit
e1242b6979
|
@ -17,6 +17,7 @@
|
||||||
removeRegExp: /[0-9.(),;:!?%#$¿'"_+=\\\/-]+/g,
|
removeRegExp: /[0-9.(),;:!?%#$¿'"_+=\\\/-]+/g,
|
||||||
wordsRegExp: /\S\s+/g,
|
wordsRegExp: /\S\s+/g,
|
||||||
charactersRegExp: /\S/g,
|
charactersRegExp: /\S/g,
|
||||||
|
allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g,
|
||||||
l10n: window.wordCountL10n || {}
|
l10n: window.wordCountL10n || {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,9 +27,9 @@
|
||||||
type = type || this.settings.l10n.type || 'words';
|
type = type || this.settings.l10n.type || 'words';
|
||||||
|
|
||||||
if ( text ) {
|
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.spaceRegExp, ' ' );
|
||||||
text = text.replace( this.settings.removeRegExp, '' );
|
text = text.replace( this.settings.removeRegExp, '' );
|
||||||
|
|
||||||
|
|
|
@ -1,47 +1,47 @@
|
||||||
( function( QUnit ) {
|
( function( QUnit, wordCounter ) {
|
||||||
var wordCounter = new window.wp.utils.WordCounter();
|
|
||||||
|
|
||||||
QUnit.module( 'word-count' );
|
QUnit.module( 'word-count' );
|
||||||
|
|
||||||
QUnit.test( 'All.', function( assert ) {
|
QUnit.test( 'All.', function( assert ) {
|
||||||
var tests = [
|
_.each( [
|
||||||
{
|
{
|
||||||
message: 'Basic test.',
|
message: 'Basic test.',
|
||||||
string: 'one two three',
|
string: 'one two three',
|
||||||
wordCount: 3,
|
words: 3,
|
||||||
charCount: 11
|
characters: 11,
|
||||||
|
all: 13
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: 'HTML tags.',
|
message: 'HTML tags.',
|
||||||
string: 'one <em class="test">two</em><br />three',
|
string: 'one <em class="test">two</em><br />three',
|
||||||
wordCount: 3,
|
words: 3,
|
||||||
charCount: 11
|
characters: 11,
|
||||||
|
all: 12
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: 'Line breaks.',
|
message: 'Line breaks.',
|
||||||
string: 'one\ntwo\nthree',
|
string: 'one\ntwo\nthree',
|
||||||
wordCount: 3,
|
words: 3,
|
||||||
charCount: 11
|
characters: 11,
|
||||||
|
all: 11
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: 'Encoded spaces.',
|
message: 'Encoded spaces.',
|
||||||
string: 'one two three',
|
string: 'one two three',
|
||||||
wordCount: 3,
|
words: 3,
|
||||||
charCount: 11
|
characters: 11,
|
||||||
|
all: 13
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
message: 'Punctuation.',
|
message: 'Punctuation.',
|
||||||
string: 'It\'s two three... 4?',
|
string: 'It\'s two three... 4?',
|
||||||
wordCount: 3,
|
words: 3,
|
||||||
charCount: 11
|
characters: 11,
|
||||||
|
all: 14
|
||||||
}
|
}
|
||||||
];
|
], function( test ) {
|
||||||
|
_.each( [ 'words', 'characters', 'all' ], function( type ) {
|
||||||
var i = tests.length;
|
assert.equal( wordCounter.count( test.string, type ), test[ type ], test.message + ' (' + type + ')' );
|
||||||
|
} );
|
||||||
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)' );
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
} )( window.QUnit );
|
} )( window.QUnit, new window.wp.utils.WordCounter() );
|
||||||
|
|
Loading…
Reference in New Issue