On French wiki we have an enclosing button « <selected text> » (notice the spaces), which is highly used. But because of typographic automatic corrections, the normal spaces get replaced with non-breaking spaces in the generated toolbar. Thus, the button inserts non-breaking spaces instead of the expected normal spaces. This is undesirable and causes us many troubles. The expected behaviour would be to have normal spaces in the wikicode, which get automatically converted to non-breaking spaces when displaying the page (and only at that time).
The attached patch would let adding the following workaround in local script:
mw.hook( 'wikipage.content' ).add( function ( $content ) { $content.find( 'a.mw-charinsert-item' ).each( function () { var $item = $( this ); if ( $item.data( 'mw-charinsert-start' ) === '«\xA0' && $item.data( 'mw-charinsert-end' ) === '\xA0»' ) { $item.data( 'mw-charinsert-start', '« ' ); $item.data( 'mw-charinsert-end', ' »' ); } } ); } );
The above code would work whether it's executed before or after the javascript bootstrap of CharInsert. Without the attached patch, the same workaround would be much more complex.