去除UEditorField中自动生成的p标签

在项目中,一个文章修改模块用到ueditor,

但是每次修改完文章点击保存后,ueditor就会自动套上一个p标签,

多次修改后,ueditor就会不断的在外层套一个p标签,以至于明明没有修改,但是它却不断的换行。

方法一:(尝试失败)

不允许修改ueditor默认源码的配置,只能选择覆盖掉。

<!--覆盖ueditor自动生成的p标签-->

var editor = UE.getEditor('editor',{     

enterTag :'br'  

});  

方法二:(找到文本模块中DajngoUEditor文件中的ueditor.all.js,尝试失败)

将自动生成p标签的内容全部注释掉

//进入编辑器的li要套p标签

    me.addInputRule(function(root){

//        utils.each(root.getNodesByTagName('li'),function(li){

//            var tmpP = UE.uNode.createElement('p');

//            for(var i= 0,ci;ci=li.children[i];){

//                if(ci.type == 'text' || dtd.p[ci.tagName]){

//                    tmpP.appendChild(ci);

//                }else{

//                    if(tmpP.firstChild()){

//                        li.insertBefore(tmpP,ci);

//                        tmpP = UE.uNode.createElement('p');

//                        i = i + 2;

//                    }else{

//                        i++;

//                    }

//

//                }

//            }

//            if(tmpP.firstChild() && !tmpP.parentNode || !li.firstChild()){

//                li.appendChild(tmpP);

//            }

//trace:3357

//p不能为空

//            if (!tmpP.firstChild()) {

//                tmpP.innerHTML(browser.ie ? ' ' : '
')

//            }

//去掉末尾的空白

//            var p = li.firstChild();

//            var lastChild = p.lastChild();

//            if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){

//                p.removeChild(lastChild)

//            }

//        });


方法三:  加“|safe”

感谢原出处

https://www.jianshu.com/p/5584c65b675b

之前:

<div class="jieshao">

    <span class="jieshao_banner">商品介绍</span>

    <div class="goods_detailcontent">{{goods.gdetailcontent}}</div>

</div>


上图的文字自动追加了<p>标签解决方法是在前端引用时加入|safe:

之后:

<div class="goods_detailcontent">{{goods.gdetailcontent |safe}}</div>


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。