UEditor纯文本粘贴时自定义格式化内容

-----------时间略紧迫,随便记一下----------

ueditor.all.js文件下大概uNode.prototype(大概在8843行)下添加去除属性的方法

/**
         * @description: 删除节点属性
         * @param {*} name
         * @return {*}
         */
        removeAttr: function(node, name) {
            if(name.indexOf(',') === -1) {
                delete node.attrs[name]
            } else {
                var attrNameList = name.split(',')
                attrNameList.forEach(item => {
                    delete node.attrs[item]
                })
            }
        },

在引用的配置js中配置 默认纯文本粘贴模式打开

//粘贴只保留标签,去除标签所有属性
retainOnlyLabelPasted: true,
//getContent时,是否删除空的inlineElement节点(包括嵌套的情况)
autoClearEmptyNode : true, 
//是否默认为纯文本粘贴。false为不使用纯文本粘贴,true为使用纯文本粘贴
pasteplain:true,
//纯文本粘贴模式下的过滤规则
filterTxtRules: (function () {
          return {
            // 直接删除及其字节点内容
            '-': 'script style object iframe embed input select',
            'p': function (node) {
              node.tagName = 'p'
              node.removeAttr(node, 'style')
            },
            'br': { $: {} },
            'div': { '$': {} },
            'li': { '$': {} },
            'caption': function (node) {
              node.tagName = 'p'
              node.removeAttr(node, 'style')
            },
            'table': function (node) {
              node.tagName = 'table'
              node.setAttr('border', '1')
              node.removeAttr(node, 'style')
            },
            'tbody': function (node) {
              node.tagName = 'tbody'
              node.removeAttr(node, 'style')
            },
            'th': function (node) {
              node.tagName = 'th'
              node.removeAttr(node, 'style')
            },
            'tr': function (node) {
              node.tagName = 'tr'
              node.removeAttr(node, 'style')
            },
            'td': function (node) {
              node.tagName = 'td'
              node.setAttr('rowspan', node.attrs.rowspan)
              node.removeAttr(node, 'style')
            },
            'h1': function (node) {
              node.tagName = 'h1'
              node.removeAttr(node, 'style')
            },
            'h2': function (node) {
              node.tagName = 'h2'
              node.removeAttr(node, 'style')
            },
            'h3': function (node) {
              node.tagName = 'h3'
              node.removeAttr(node, 'style')
            },
            'h4': function (node) {
              node.tagName = 'h4'
              node.removeAttr(node, 'style')
            },
            'h5': function (node) {
              node.tagName = 'h5'
              node.removeAttr(node, 'style')
            },
            'h6': function (node) {
              node.tagName = 'h6'
              node.removeAttr(node, 'style')
            },
            'audio': function (node) {
              node.tagName = 'audio'
            },
            'video': function (node) {
              node.tagName = 'video'
            },
            'img': function (node) {
              node.tagName = 'img'
            },
            'map': function (node) {
              node.tagName = 'map'
            },
            'area': function (node) {
              node.tagName = 'area'
            },
            'canvas': function (node) {
              node.tagName = 'canvas'
            },
            'svg': function (node) {
              node.tagName = 'svg'
            }
          }
        }())

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值