CKEditor BR tag issie
Issue with CKEditor 4.x where multiple BR tags pasted into source field get replaced with NBSPs, after toggling from source to wysiwyg and back.
HTML
<script src="http://nightly.ckeditor.com/13-03-21-20-18/standard/ckeditor.js"></script>
<p>http://nightly.ckeditor.com/13-03-21-20-18/standard/ckeditor.js</p>
<textarea id="test">
<br />
<p>This is a paragraph of text.</p>
<br />
<br />
<p>Second paragraph of text.</p>
</textarea>
JavaScript
var options = {
allowedContent: true,
fillEmptyBlocks: function(element){
// console.info('element: ', element);
},
autoParagraph: false,
height: 200,
enterMode: CKEDITOR.ENTER_BR,
shiftEnterMode: CKEDITOR.ENTER_P,
resize_enabled: false
};
var editor = CKEDITOR.replace('test', options);
editor.on('pluginsLoaded' , function( evt ){
var previousNext = false;
evt.editor.dataProcessor.htmlFilter.addRules({
elements :{
$ : function( element ) {
if (element.previous || element.next) {
if (previousNext && previousNext.value == ' ' && element.previous && element.previous.name =='br') {
var helper = new CKEDITOR.htmlParser.text('<br>');
helper.insertBefore(element);
previousNext.remove();
}
previousNext = element.next;
}
}
}
});
var counter = 0;
evt.editor.dataProcessor.dataFilter.addRules({
elements :{
br : function( element ) {
if(element.next && (element.next.value == ' ' || element.next.name == 'br')){
counter++;
return;
}
if(counter <= 1){
var helper = new CKEDITOR.htmlParser.text(' ');
helper.insertAfter(element);
}
counter = 0;
}
}
});
});