Changeset 33344
- Timestamp:
- 07/21/2015 03:23:45 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/word-count.js
r33320 r33344 15 15 16 16 if ( shortcodes && shortcodes.length ) { 17 this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g i' );17 this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' ); 18 18 } 19 19 } … … 21 21 WordCounter.prototype.settings = { 22 22 HTMLRegExp: /<\/?[a-z][^>]*?>/gi, 23 HTMLcommentRegExp: /<!--[\s\S]*?-->/g, 23 24 spaceRegExp: / | /gi, 24 connectorRegExp: /--|\u2014/gi, 25 HTMLEntityRegExp: /&\S+?;/g, 26 connectorRegExp: /--|\u2014/g, 25 27 removeRegExp: new RegExp( [ 26 28 '[', … … 61 63 wordsRegExp: /\S\s+/g, 62 64 charactersRegExp: /\S/g, 63 allRegExp: /[^\f\n\r\t\v\u00 ad\u2028\u2029]/g,65 allRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g, 64 66 l10n: window.wordCountL10n || {} 65 67 }; … … 68 70 var count = 0; 69 71 70 type = type || this.settings.l10n.type || 'words'; 72 type = type || this.settings.l10n.type; 73 74 if ( type !== 'characters' && type !== 'all' ) { 75 type = 'words'; 76 } 71 77 72 78 if ( text ) { … … 74 80 75 81 text = text.replace( this.settings.HTMLRegExp, '\n' ); 82 text = text.replace( this.settings.HTMLcommentRegExp, '' ); 76 83 77 84 if ( this.settings.shortcodesRegExp ) { … … 82 89 83 90 if ( type === 'words' ) { 91 text = text.replace( this.settings.HTMLEntityRegExp, '' ); 84 92 text = text.replace( this.settings.connectorRegExp, ' ' ); 85 93 text = text.replace( this.settings.removeRegExp, '' ); 86 94 } else { 95 text = text.replace( this.settings.HTMLEntityRegExp, 'a' ); 87 96 text = text.replace( this.settings.astralRegExp, 'a' ); 88 97 } -
trunk/tests/qunit/wp-admin/js/word-count.js
r33320 r33344 59 59 characters: 1, 60 60 all: 1 61 }, 62 { 63 message: 'HTML comment.', 64 string: 'one<!-- comment -->two three', 65 words: 2, 66 characters: 11, 67 all: 12 68 }, 69 { 70 message: 'HTML entity.', 71 string: '> test', 72 words: 1, 73 characters: 5, 74 all: 6 61 75 } 62 76 ], function( test ) {
Note: See TracChangeset
for help on using the changeset viewer.