Skip to content

Instantly share code, notes, and snippets.

@cfg
Created June 16, 2016 20:14
Show Gist options
  • Save cfg/1e47d24fc5a2471df0eabdb6443f5040 to your computer and use it in GitHub Desktop.
Save cfg/1e47d24fc5a2471df0eabdb6443f5040 to your computer and use it in GitHub Desktop.
Simple/hacky bookmarklet to replace hidden nbsp (\u00A0) characters in a WordPress tinymce editor
javascript:(function() {
if( !window.tinymce ) { alert('tinymce was not found, aborting.' ); return; }
var el = tinymce.get('content');
if( !el ) { alert('Unable to find the WP Edit box - aborting.' ); return; }
var matches = el.getContent().match( /\u00A0/g );
if( ! matches || matches.length === 0 ) { alert('No hidden non-breaking spaces were found.' ); return; }
if( matches && matches.length >= 1 ) {
if( confirm( 'Found ' + matches.length + ' non-breaking space character' + ( matches.length === 1 ? '' : 's' ) + ' replace them with a normal space?' ) ) {
el.setContent( el.getContent().replace( /\u00A0/g, ' ' ) );
alert('Done - save the post and run this again.');
} else {
alert('Aborting, no characters will be replaced.');
}
}
})();
/* Minified:
javascript:!function(){if(!window.tinymce)return void alert("tinymce was not found, aborting.");var e=tinymce.get("content");if(!e)return void alert("Unable to find the WP Edit box - aborting.");var n=e.getContent().match(/\u00A0/g);return n&&0!==n.length?void(n&&n.length>=1&&(confirm("Found "+n.length+" non-breaking space character"+(1===n.length?"":"s")+" replace them with a normal space?")?(e.setContent(e.getContent().replace(/\u00A0/g," ")),alert("Done - save the post and run this again.")):alert("Aborting, no characters will be replaced."))):void alert("No hidden non-breaking spaces were found.")}();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment