Ticket #30966: 30966.14.patch
File 30966.14.patch, 2.5 KB (added by , 9 years ago) |
---|
-
src/wp-admin/js/word-count.js
14 14 shortcodes = this.settings.l10n.shortcodes; 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 } 20 20 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 '[', 27 29 // Basic Latin (extract) … … 60 62 astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, 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 }; 66 68 … … 73 75 text = text + '\n'; 74 76 75 77 text = text.replace( this.settings.HTMLRegExp, '\n' ); 78 text = text.replace( this.settings.HTMLcommentRegExp, '' ); 76 79 77 80 if ( this.settings.shortcodesRegExp ) { 78 81 text = text.replace( this.settings.shortcodesRegExp, '\n' ); … … 81 84 text = text.replace( this.settings.spaceRegExp, ' ' ); 82 85 83 86 if ( type === 'words' ) { 87 text = text.replace( this.settings.HTMLEntityRegExp, '' ); 84 88 text = text.replace( this.settings.connectorRegExp, ' ' ); 85 89 text = text.replace( this.settings.removeRegExp, '' ); 86 90 } else { 91 text = text.replace( this.settings.HTMLEntityRegExp, 'a' ); 87 92 text = text.replace( this.settings.astralRegExp, 'a' ); 88 93 } 89 94 -
tests/qunit/wp-admin/js/word-count.js
58 58 words: 1, 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 ) { 63 77 _.each( [ 'words', 'characters', 'all' ], function( type ) {