Editor: word count: exclude shortcodes
Props desaiuditd, adamsilverstein, azaozz and iseulde. Fixes #27386. See #30966. Built from https://develop.svn.wordpress.org/trunk@33299 git-svn-id: http://core.svn.wordpress.org/trunk@33271 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
dac985cdc4
commit
f00d1e63f1
|
@ -1,6 +1,7 @@
|
|||
( function() {
|
||||
function WordCounter( settings ) {
|
||||
var key;
|
||||
var key,
|
||||
shortcodes;
|
||||
|
||||
if ( settings ) {
|
||||
for ( key in settings ) {
|
||||
|
@ -9,6 +10,12 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
shortcodes = this.settings.l10n.shortcodes;
|
||||
|
||||
if ( shortcodes && shortcodes.length ) {
|
||||
this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'gi' );
|
||||
}
|
||||
}
|
||||
|
||||
WordCounter.prototype.settings = {
|
||||
|
@ -65,6 +72,11 @@
|
|||
text = text + '\n';
|
||||
|
||||
text = text.replace( this.settings.HTMLRegExp, '\n' );
|
||||
|
||||
if ( this.settings.shortcodesRegExp ) {
|
||||
text = text.replace( this.settings.shortcodesRegExp, '\n' );
|
||||
}
|
||||
|
||||
text = text.replace( this.settings.spaceRegExp, ' ' );
|
||||
|
||||
if ( type === 'words' ) {
|
||||
|
|
|
@ -1 +1 @@
|
|||
!function(){function a(a){var b;if(a)for(b in a)a.hasOwnProperty(b)&&(this.settings[b]=a[b])}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"),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"),a=a.replace(this.settings.spaceRegExp," "),"words"===b&&(a=a.replace(this.settings.connectorRegExp," "),a=a.replace(this.settings.removeRegExp,"")),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("|")+")[^\\]]*?\\]","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"),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.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}();
|
|
@ -400,7 +400,8 @@ function wp_default_scripts( &$scripts ) {
|
|||
/* translators: If your word count is based on single characters (East Asian characters),
|
||||
enter 'characters', or 'all' to include spaces. Otherwise, enter 'words'.
|
||||
Do not translate into your own language. */
|
||||
'type' => _x( 'words', 'word count: words, characters or all?' )
|
||||
'type' => _x( 'words', 'word count: words, characters or all?' ),
|
||||
'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array()
|
||||
) );
|
||||
|
||||
$scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 );
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-beta3-33298';
|
||||
$wp_version = '4.3-beta3-33299';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue