zoukankan      html  css  js  c++  java
  • 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';

     

  • 相关阅读:
    下载的谷歌浏览器打不开设置等 报崩溃 新版谷歌crx插件不让拖拽安装问题 cnpm安装问题
    webpack相关面试题
    京东改版提高的性能方面
    对于程序员来说拿到需求之后的那些事(项目管理、需求预估工期等等)
    前端迈向全栈的知识储备路程
    最近的Taro小程序和JD小程序以及原生小程序对比优势
    【转】vmware安装ubuntu详细步骤
    解决主机telnet vmware(ubuntu)不通的问题
    Byte、KB、MB、GB、TB、PB、EB、ZB、YB、DB、NB
    一些协议的链接
  • 原文地址:https://www.cnblogs.com/weizaiyes/p/8663300.html
Copyright © 2011-2022 走看看