如何强制CKEditor保存< br>标签
我在标准软件包中使用的是最新版本的CKEditor(迄今为止为4.7),并且我希望能够强制它保留换行符(< br>
)。
I am using the latest version of CKEditor (4.7 to date) with the standard package, and I want to be able to force it to preserve line break elements (<br>
).
我尝试使用以下配置,但没有成功:
I have attempted to use the following config, without success:
CKEDITOR.replace('ck', {
allowedContent: true,
enterMode: CKEDITOR.ENTER_BR
});
您可以看到在此jsfiddle 中,当您打开源代码模式时,< br>
标记已替换为& ; nbsp;
。
As you can see in this jsfiddle, when you open Source mode, <br>
tags have been replaced with a
.
如何实现?
对此给出了一种解决方法(或至少是部分解决方法) CKEditor票证,它强制CKEditor保留< br>
标签:
A workaround (or at least partial workaround) was given on this CKEditor ticket, which forces the CKEditor to preserve <br>
tags:
editor.on( 'pluginsLoaded', function( evt ){
evt.editor.dataProcessor.dataFilter.addRules({
elements :{
br : function( element ) {
//if next element is BR or <!--cke_br_comment-->, ignore it.
if( element && element.next && ( element.next.name == 'br' || element.next.value == 'cke_br_comment' ) ){
return;
}else {
var comment = new CKEDITOR.htmlParser.comment( 'cke_br_comment' );
comment.insertAfter( element );
}
}
}
});
evt.editor.dataProcessor.htmlFilter.addRules({
comment : function( value, node ) {
if( value.indexOf('cke_br_comment') >= 0 ) {
return false;
}
}
});
编辑:您可能还需要检查我的其他答案,根据您的需求可能会更好。
you might also want to check my other answer which may work better depending on your needs.