如何强制CKEditor保存< br>标签 [英] How to force CKEditor to preserve <br> tags

查看:54
本文介绍了如何强制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 &nbsp;.

如何实现?

推荐答案

对此给出了一种解决方法(或至少是部分解决方法) 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.

这篇关于如何强制CKEditor保存&lt; br&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆