百度编辑器去除一些无用标签方法

news/2024/7/17 12:53:16

1、去掉每个li的中加<p></p>的方法:

直接搜索 //进入编辑器的li要套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 ? '&nbsp;' : '<br/>')
        //    }
        //    //去掉末尾的空白
        //    var p = li.firstChild();
        //    var lastChild = p.lastChild();
        //    if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){
        //        p.removeChild(lastChild)
        //    }
        //});
        //if(me.options.autoTransWordToList){
        //    var orderlisttype = {
        //            'num1':/^\d+\)/,
        //            'decimal':/^\d+\./,
        //            'lower-alpha':/^[a-z]+\)/,
        //            'upper-alpha':/^[A-Z]+\./,
        //            'cn':/^[\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+[\u3001]/,
        //            'cn2':/^\([\u4E00\u4E8C\u4E09\u56DB\u516d\u4e94\u4e03\u516b\u4e5d]+\)/
        //        },
        //        unorderlisttype = {
        //            'square':'n'
        //        };
        //    function checkListType(content,container){
        //        var span = container.firstChild();
        //        if(span &&  span.type == 'element' && span.tagName == 'span' && /Wingdings|Symbol/.test(span.getStyle('font-family'))){
        //            for(var p in unorderlisttype){
        //                if(unorderlisttype[p] == span.data){
        //                    return p
        //                }
        //            }
        //            return 'disc'
        //        }
        //        for(var p in orderlisttype){
        //            if(orderlisttype[p].test(content)){
        //                return p;
        //            }
        //        }

        //    }
        //    utils.each(root.getNodesByTagName('p'),function(node){
        //        if(node.getAttr('class') != 'MsoListParagraph'){
        //            return
        //        }

        //        //word粘贴过来的会带有margin要去掉,但这样也可能会误命中一些央视
        //        node.setStyle('margin','');
        //        node.setStyle('margin-left','');
        //        node.setAttr('class','');

        //        function appendLi(list,p,type){
        //            if(list.tagName == 'ol'){
        //                if(browser.ie){
        //                    var first = p.firstChild();
        //                    if(first.type =='element' && first.tagName == 'span' && orderlisttype[type].test(first.innerText())){
        //                        p.removeChild(first);
        //                    }
        //                }else{
        //                    p.innerHTML(p.innerHTML().replace(orderlisttype[type],''));
        //                }
        //            }else{
        //                p.removeChild(p.firstChild())
        //            }

        //            var li = UE.uNode.createElement('li');
        //            li.appendChild(p);
        //            list.appendChild(li);
        //        }
        //        var tmp = node,type,cacheNode = node;

        //        if(node.parentNode.tagName != 'li' && (type = checkListType(node.innerText(),node))){

        //            var list = UE.uNode.createElement(me.options.insertorderedlist.hasOwnProperty(type) ? 'ol' : 'ul');
        //            if(customStyle[type]){
        //                list.setAttr('class','custom_'+type)
        //            }else{
        //                list.setStyle('list-style-type',type)
        //            }
        //            while(node && node.parentNode.tagName != 'li' && checkListType(node.innerText(),node)){
        //                tmp = node.nextSibling();
        //                if(!tmp){
        //                    node.parentNode.insertBefore(list,node)
        //                }
        //                appendLi(list,node,type);
        //                node = tmp;
        //            }
        //            if(!list.parentNode && node && node.parentNode){
        //                node.parentNode.insertBefore(list,node)
        //            }
        //        }
        //        var span = cacheNode.firstChild();
        //        if(span && span.type == 'element' && span.tagName == 'span' && /^\s*(&nbsp;)+\s*$/.test(span.innerText())){
        //            span.parentNode.removeChild(span)
        //        }
        //    })
        //}

    });

2、去掉内容编辑自动套P标签:

搜索修改成false:allowDivTransToP: false
再搜索并修改以下:
//编辑器不能为空内容

if (domUtils.isEmptyNode(me.body)) {
    me.body.innerHTML = '<p>' + (browser.ie ? '' : '<br/>') + '</p>';
}
更改为:

 

if (domUtils.isEmptyNode(me.body)) {
    me.body.innerHTML = browser.ie ? '' : '<br/>';
}

 

 


http://www.niftyadmin.cn/n/2458196.html

相关文章

css selector什么意思

css selector指的是css选择器&#xff0c;是用来匹配网页中的dom元素的&#xff0c;常用选择器可分为标签名选择器、类选择器、id选择器、派生选择器、子元素选择器、分组选择器和伪元素选择器。 推荐&#xff1a;《css视频教程》 css selector指的是css 选择器&#xff0c;是用…

C++抽象编程·运算符重载与友元函数

运算符重载&#xff08;Operator overloading&#xff09; 从我们在几个前篇的类的层次介绍中可以知道&#xff0c;C可以扩展标准运算符&#xff0c;使其适用于新类型。这种技术称为运算符重载。 例如&#xff0c;字符串类重载运算符&#xff0c;使其在应用于字符串时的行为会有…

PHP生成伪随机数

版本要求最低PHP7&#xff0c;如果对生成随机数要求比较多&#xff0c;可以选择使用zend-math、random-lib或random_compat库。(几乎所有PHP库都可以在 https://packagist.org 搜索到) /*** 获取随机数字** author 剑心 <[0x00gcgmail.com]>** param int $size…

C++ 拷贝构造

在C存在拷贝构造函数&#xff0c;拷贝构造函数与不同构造函数形成重载&#xff08;这一点很重要&#xff09;&#xff0c;这就意味着&#xff08;要么class入口为普通构造函数&#xff0c;要么为拷贝构造函数&#xff0c;不可能2个都会执行的&#xff09;。好了 &#xff0c; 下…

分享一些VSCode开发常用插件

本篇文章给大家介绍分享一些VSCode开发必备常用插件。有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对大家有所帮助。 相关推荐&#xff1a;《vscode教程》 Visual Studio Code必备常用插件 红色为强力推荐&#xff0c;不容错过 o(∩_∩)o Chinese (S…

【Java】【高精度】【组合数】【递推】poj1737 Connected Graph

http://blog.csdn.net/sdj222555/article/details/12453629 这个递推可以说是非常巧妙了。 import java.util.*; import java.io.*; import java.math.*;public class Main{static BigInteger[] gnew BigInteger[60];static BigInteger[] fnew BigInteger[60];static BigIntege…

jquery LigerUI是什么?

jQuery LigerUI是基于jQuery而设计的一系列UI插件集合&#xff0c;其核心设计目标是快速开发、使用简单、功能强大、轻量级、易扩展&#xff0c;使用UI可以帮助开发者快速地创建友好的用户界面。 相关推荐&#xff1a;《jQuery教程》 jquery LigerUI 快速开发UI框架 LigerUI 是…

兼容性—IE6/7下带有overflow:hidden属性的父级元素包不住带有position:relative属性的子元素...

IE6/7下带有overflow:hidden属性的父级元素包不住带有position&#xff1a;relative属性的子元素 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><title>Document</title><style>.box{width: 20…