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,
|
||||
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, '' );
|
||||
|
||||
|
@ -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 <em class="test">two</em><br />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() );
|
||||
|
Loading…
Reference in New Issue
Block a user