ueditor的bug

1)过滤script style标签
ueditor.all.js
allowDivTransToP:false

ueditor.config.js
,allowDivTransToP:false //允许进入编辑器的div标签自动变成p标签
//,rgb2Hex:true //默认产出的数据中的color自动从rgb格式变成16进制格式

// xss 过滤是否开启,inserthtml等操作
,xssFilterRules: false
//input xss过滤
,inputXssFilter: false
//output xss过滤
,outputXssFilter: false
// xss过滤白名单 名单来源: https://raw.githubusercontent.com/leizongmin/js-xss/master/lib/default.js
,whitList: {
div:[],
style:[],
script:[],

2)空格替换问题

在Ueditor编辑器里,直接粘贴一篇编辑好的文章(包括文字、图片)或html源码时,
编辑器会自动生成 标签,这样会导致网站前端样式走样。

在ueditor.all.js文件找到上述所示代码,将 替换为‘
’即可。如下所示:

function isText(node, arr) {

if(node.parentNode.tagName == 'pre'){
//源码模式下输入html标签,不能做转换处理,直接输出
arr.push(node.data)
}else{
arr.push(notTransTagName[node.parentNode.tagName] ? utils.html(node.data) : node.data.replace(/[ ]{2}/g,'&nbsp'))
}

}

3.百度的Ueditor编辑器出于安全考虑;

用户在html模式下粘贴进去的html文档会自动被去除样式和转义

虽然安全的,但是非常不方便。 

做一下修改把这个功能去掉。 

一、打开ueditor.all.js 

二、大概9300行找到 ///plugin 编辑器默认的过滤转换机制,把下面的

'allowDivTransToP':true

值改成false。为true的时候会自动把div转成p。 

三、大概9429行,有个case 'li',这个是把li里面的样式去掉,把这个case注释掉。 

四、大概15112行 或者搜索:(//进入编辑器的li要套p标签),下面的第一个utils.each功能注释掉,这个是自动给li里面的内容

增加一个p。 注释掉,function(li){/*...............*/}函数里的内容。

五、大概14220行,

node.className = utils.trim(node.className.replace(/list-paddingleft-\w+/,'')) 

+ ' list-paddingleft-' + type;

注释掉,这个是自动给ul增加一个内置的样式。 

下面的14222

li.style.cssText && (li.style.cssText = '');

注释掉,这个是自动去除粘贴进去的代码的li的style样式 

 

至此,我们粘贴进去的html格式的ul和li就不会被转义了。 


上边是引用,下边是我多加的来满在哪里也都不加P或P里加BR等等等

15112行左右:(下边代码注释掉)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 ?  '&nbsp;'  '<br/>' )
             }
             //去掉末尾的空白
             var  p = li.firstChild();
             var  lastChild = p.lastChild();
             if (lastChild && lastChild.type ==  'text'  && /^\s*$/.test(lastChild.data)){
                 p.removeChild(lastChild)
             }
         });

10079行左右:(注释掉)[dl dd dt 元素就不会自动转成 ul li 元素了]

1
2
3
node.tagName =  'ul' ;
 
node.tagName =  'li' ;

 

转载于:https://www.cnblogs.com/weizaiyes/p/8663300.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值