迅睿CMS百度编辑器Ueditor复制粘贴去掉样式得方法
1、复制删除样式得方法,找到/api/ueditor/ueditor.config.js中得代码,对应得代码修改未如下即可
//粘贴只保留标签,去除标签所有属性 ,retainOnlyLabelPasted: true
UEditor内置了无格式粘贴的功能,只需要简单的配置即可。
1、修改ueditor.config.js,开启retainOnlyLabelPasted,并设置为true
2、开启pasteplain,并设为true
3、开启filterTxtRules过滤规则。
注意:filterTxtRules过滤规则默认只过滤p、div、li这几个标签。如果h1~h6这类标签,只是将标签体替换为p标签,并没有将标签体的样式去除。因而通过itextpdf生成pdf时时往往会出现异常。因而,较为完善的做法应该是将所有标签的样式都去掉(将过滤规则改为{$:{}})。
修改后的过滤规则:
'filterTxtRules' : function(){
  function transP(node){
      node.tagName = 'p';
      node.setStyle();
  }
  return {
      //直接删除及其字节点内容
      '-' : 'script style object iframe embed input select',
      'p': {$:{}},
      'br':{$:{}},
      'div':{$:{}},
      'li':{$:{}},
      'caption':{$:{}},
      'th':{$:{}},
      'tr':{$:{}},
      'h1':{$:{}},'h2':{$:{}},'h3':{$:{}},'h4':{$:{}},'h5':{$:{}},'h6':{$:{}},
      'td':function(node){
          //没有内容的td直接删掉
          var txt = !!node.innerText();
          if(txt){
              node[xss_clean].insertAfter(UE.uNode.createText('    '),node);
          }
          node[xss_clean].removeChild(node,node.innerText())
      }
  }
}()本文网址:https://www.dedexuexi.com/jzjc/xrjc/eckf/3781.html
本站部分文章搜集与网络,如有侵权请联系本站,转载请说明出处。














