Editor: word count: exclude HTML comments and entities
Also make sure `type` is one of the three allowed types and remove unnecessary regex flags. See #30966. Built from https://develop.svn.wordpress.org/trunk@33344 git-svn-id: http://core.svn.wordpress.org/trunk@33316 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
bf481ed496
commit
50159974c9
|
@ -14,14 +14,16 @@
|
|||
shortcodes = this.settings.l10n.shortcodes;
|
||||
|
||||
if ( shortcodes && shortcodes.length ) {
|
||||
this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'gi' );
|
||||
this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' );
|
||||
}
|
||||
}
|
||||
|
||||
WordCounter.prototype.settings = {
|
||||
HTMLRegExp: /<\/?[a-z][^>]*?>/gi,
|
||||
HTMLcommentRegExp: /<!--[\s\S]*?-->/g,
|
||||
spaceRegExp: / | /gi,
|
||||
connectorRegExp: /--|\u2014/gi,
|
||||
HTMLEntityRegExp: /&\S+?;/g,
|
||||
connectorRegExp: /--|\u2014/g,
|
||||
removeRegExp: new RegExp( [
|
||||
'[',
|
||||
// Basic Latin (extract)
|
||||
|
@ -60,19 +62,24 @@
|
|||
astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
|
||||
wordsRegExp: /\S\s+/g,
|
||||
charactersRegExp: /\S/g,
|
||||
allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g,
|
||||
allRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g,
|
||||
l10n: window.wordCountL10n || {}
|
||||
};
|
||||
|
||||
WordCounter.prototype.count = function( text, type ) {
|
||||
var count = 0;
|
||||
|
||||
type = type || this.settings.l10n.type || 'words';
|
||||
type = type || this.settings.l10n.type;
|
||||
|
||||
if ( type !== 'characters' && type !== 'all' ) {
|
||||
type = 'words';
|
||||
}
|
||||
|
||||
if ( text ) {
|
||||
text = text + '\n';
|
||||
|
||||
text = text.replace( this.settings.HTMLRegExp, '\n' );
|
||||
text = text.replace( this.settings.HTMLcommentRegExp, '' );
|
||||
|
||||
if ( this.settings.shortcodesRegExp ) {
|
||||
text = text.replace( this.settings.shortcodesRegExp, '\n' );
|
||||
|
@ -81,9 +88,11 @@
|
|||
text = text.replace( this.settings.spaceRegExp, ' ' );
|
||||
|
||||
if ( type === 'words' ) {
|
||||
text = text.replace( this.settings.HTMLEntityRegExp, '' );
|
||||
text = text.replace( this.settings.connectorRegExp, ' ' );
|
||||
text = text.replace( this.settings.removeRegExp, '' );
|
||||
} else {
|
||||
text = text.replace( this.settings.HTMLEntityRegExp, 'a' );
|
||||
text = text.replace( this.settings.astralRegExp, 'a' );
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(){function a(a){var b,c;if(a)for(b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b]);c=this.settings.l10n.shortcodes,c&&c.length&&(this.settings.shortcodesRegExp=new RegExp("\\[\\/?(?:"+c.join("|")+")[^\\]]*?\\]","gi"))}a.prototype.settings={HTMLRegExp:/<\/?[a-z][^>]*?>/gi,spaceRegExp:/ | /gi,connectorRegExp:/--|\u2014/gi,removeRegExp:new RegExp(["[","!-@[-`{-~","\x80-\xbf\xd7\xf7","\u2000-\u2bff","\u2e00-\u2e7f","]"].join(""),"g"),astralRegExp:/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,wordsRegExp:/\S\s+/g,charactersRegExp:/\S/g,allRegExp:/[^\f\n\r\t\v\u00ad\u2028\u2029]/g,l10n:window.wordCountL10n||{}},a.prototype.count=function(a,b){var c=0;return b=b||this.settings.l10n.type||"words",a&&(a+="\n",a=a.replace(this.settings.HTMLRegExp,"\n"),this.settings.shortcodesRegExp&&(a=a.replace(this.settings.shortcodesRegExp,"\n")),a=a.replace(this.settings.spaceRegExp," "),"words"===b?(a=a.replace(this.settings.connectorRegExp," "),a=a.replace(this.settings.removeRegExp,"")):a=a.replace(this.settings.astralRegExp,"a"),a=a.match(this.settings[b+"RegExp"]),a&&(c=a.length)),c},window.wp=window.wp||{},window.wp.utils=window.wp.utils||{},window.wp.utils.WordCounter=a}();
|
||||
!function(){function a(a){var b,c;if(a)for(b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b]);c=this.settings.l10n.shortcodes,c&&c.length&&(this.settings.shortcodesRegExp=new RegExp("\\[\\/?(?:"+c.join("|")+")[^\\]]*?\\]","g"))}a.prototype.settings={HTMLRegExp:/<\/?[a-z][^>]*?>/gi,HTMLcommentRegExp:/<!--[\s\S]*?-->/g,spaceRegExp:/ | /gi,HTMLEntityRegExp:/&\S+?;/g,connectorRegExp:/--|\u2014/g,removeRegExp:new RegExp(["[","!-@[-`{-~","\x80-\xbf\xd7\xf7","\u2000-\u2bff","\u2e00-\u2e7f","]"].join(""),"g"),astralRegExp:/[\uD800-\uDBFF][\uDC00-\uDFFF]/g,wordsRegExp:/\S\s+/g,charactersRegExp:/\S/g,allRegExp:/[^\f\n\r\t\v\u00AD\u2028\u2029]/g,l10n:window.wordCountL10n||{}},a.prototype.count=function(a,b){var c=0;return b=b||this.settings.l10n.type,"characters"!==b&&"all"!==b&&(b="words"),a&&(a+="\n",a=a.replace(this.settings.HTMLRegExp,"\n"),a=a.replace(this.settings.HTMLcommentRegExp,""),this.settings.shortcodesRegExp&&(a=a.replace(this.settings.shortcodesRegExp,"\n")),a=a.replace(this.settings.spaceRegExp," "),"words"===b?(a=a.replace(this.settings.HTMLEntityRegExp,""),a=a.replace(this.settings.connectorRegExp," "),a=a.replace(this.settings.removeRegExp,"")):(a=a.replace(this.settings.HTMLEntityRegExp,"a"),a=a.replace(this.settings.astralRegExp,"a")),a=a.match(this.settings[b+"RegExp"]),a&&(c=a.length)),c},window.wp=window.wp||{},window.wp.utils=window.wp.utils||{},window.wp.utils.WordCounter=a}();
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-beta3-33343';
|
||||
$wp_version = '4.3-beta3-33344';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue