I’ve got the following macro button defined to wrap a selection in a shortcode in the wp_editor visual editor:
(function() {
tinymce.create('tinymce.plugins.ingredient_name', {
init : function(ed, url){
ed.addButton('ingredient_name', {
title : 'Tag ingredient',
onclick : function() {
var text=ed.selection.getContent({'format':'text'});
ed.execCommand('mceInsertContent',false,'[ingredient_name]' + text + '[/ingredient_name]');
},
image: url + "/name.png"
});
}
});
tinymce.PluginManager.add('ingredient_name', tinymce.plugins.ingredient_name);
})();
The macro works as intended, except that tinymce is also inserting   in front of the resulting shortcode. So, instead of this result:
1 [ingredient_name]pound[/ingredient_name] salami
I get this:
1 [ingredient_name]pound[/ingredient_name] salami
this then somehow gets mangled when inserting to the DB, and rendered to the template, I get ‘1Ã pound salami’. I can go back and remove the offending  ’s, but I’d prefer tinyMCE not insert that entity in the first place. Any ideas?
well, it turned out not to be an issue with tiny mce at all, rather php DOMdocument that was filtering tinyMCE’s output, interpreted in the wrong charset, then passing garbage characters to the page.
Fun!
The TinyMCE WYSIWYG editor convert space symbols into
entities by default. It causes because the defaultentities
property is set to convert space symbols into
entities:To resolve this issue, you should redefine the
entities
init property. For example:To initialize TinyMCE options in WordPress, you have to add your own hook to
tiny_mce_before_init
filter:The full list of values, which you can adjust, you can read at TinyMCE Configuration page. And the last link for entities option.