Baidu rich text Ueditor will issue additional tags

We write text using ueditor back sometimes this is the label, but directly into the text is written to the input box, and each submission will append a tag

This is because you save the database text tag is escaped, such as: & lt; p & gt; & amp; nbsp; & amp; nbsp; & amp; nbsp; & amp; nbsp; & amp; nbsp; & amp; nbsp; & amp; nbsp; & amp; nbsp ;,

The escape character through ueditor.all.js will convert directly into setContent the label when the text is written back to the input box, and each time setContent will write back to you automatically add a label p, then we

To advance to escape the label, so ueditor write back when he thought it was a label, rather than escaping to a text written back to the input box, when you have returned from the label ueditor will not add p tags

the setContent: function (HTML, isAppendTo, notFireSelectionchange) { 
            HTML = strDiscode (HTML); // escaping incoming text
             var Me = the this ; 

            me.fireEvent ( 'beforesetcontent' , HTML);
             var the root = UE.htmlparser (HTML ); // This will convert the text into html uNode node, if not it will escape into the text input box written directly 
            me.filterInputRule (the root); 

            html = root.toHtml (); // here escape node in the text 

            me.body.innerHTML = (isAppendTo me.body.innerHTML:? '') + HTML; 


            function isCdataDiv (Node) {
                return  node.tagName == 'DIV' && node.getAttribute('cdata_tag');
            }
            //给文本或者inline节点套p标签
            if (me.options.enterTag == 'p') {

                var child = this.body.firstChild, tmpNode;
                if (!child || child.nodeType == 1 &&
                    (dtd.$cdata[child.tagName] || isCdataDiv(child) ||
                        domUtils.isCustomeNode(child)
                        )
                    && child === this.body.lastChild) {
                    this.body.innerHTML = '<p>' + (browser.ie ? '&nbsp;' : '<br/>') + '</p>' + this.body.innerHTML;

                } else {
                    var p = me.document.createElement('p');
                    while (child) {
                        while (child && (child.nodeType == 3 || child.nodeType == 1 && dtd.p[child.tagName] && !dtd.$cdata[child.tagName])) {
                            tmpNode = child.nextSibling;
                            p.appendChild(child);
                            child = tmpNode;
                        }
                        if (p.firstChild) {
                            if (!child) {
                                me.body.appendChild(p);
                                break;
                            } else {
                                child.parentNode.insertBefore(p, child);
                                p = me.document.createElement('p');
                            }
                        }
                        child = child.nextSibling;
                    }
                }
            }
            me.fireEvent('aftersetcontent');
            me.fireEvent('contentchange');

            !notFireSelectionchange &&me._selectionChange ();
             // Clear saved selection 
            me._bakRange = me._bakIERange = me._bakNativeRange = null ;
             // the trace: After 1742 setContent gecko focus can be obtained 
            var geckoSel;
             IF (browser.gecko && (= geckoSel the this .selection.getNative ())) { 
                geckoSel.removeAllRanges (); 
            } 
            IF (me.options.autoSyncData) { 
                me.form && the setValue (me.form, Me); 
            } 
        },

Escape method

// HTML 支持的数学符号
    function strNumDiscode(str) {
        str = str.replace(/&forall;/g, '∀');
        str = str.replace(/&part;/g, '∂');
        str = str.replace(/&exists;/g, '∃');
        str = str.replace(/&empty;/g, '∅');
        str = str.replace(/&nabla;/g, '∇');
        str = str.replace(/&isin;/g, '∈');
        str = str.replace(/&notin;/g, '∉');
        str = str.replace(/&ni;/g, '∋');
        str = str.replace(/&prod;/g, '∏');
        str = str.replace(/&sum;/g, '∑');
        str = str.replace(/&minus;/g, '−');
        str = str.replace(/&lowast;/g, '∗');
        str = str.replace(/&radic;/g, '√');
        str = str.replace(/&prop;/g, '∝');
        str = str.replace(/&infin;/g, '∞');
        str = str.replace(/&ang;/g, '∠');
        str = str.replace(/&and;/g, '∧');
        str = str.replace(/&or;/g, '∨');
        str = str.replace(/&cap;/g, '∩');
        str = str.replace(/&cap;/g, '∪');
        str = str.replace(/&int;/g, '∫');
        str = str.replace(/&there4;/g, '∴');
        str = str.replace(/&sim;/g, '∼');
        str = str.replace(/&cong;/g, '≅');
        str = str.replace(/&asymp;/g, '≈');
        str = str.replace(/&ne;/g, '≠');
        str = str.replace(/&le;/g, '≤');
        str = str.replace(/&ge;/g, '≥');
        str = str.replace(/&sub;/g, '⊂');
        str = str.replace(/&sup;/g, '⊃'
        str = str.replace(/⊄/g, '⊄');
        str = str.replace(/⊆/g, '⊆');
        str = str.replace(/⊇/g, '⊇');
        str = str.replace(/⊕/g, '⊕');
        str = str.replace(/⊗/g, '⊗');
        str = str.replace(/⊥/g, '⊥');
        str = str.replace(/⋅/g, '⋅');
        return str;
    }

//HTML 支持的希腊字母
    function strGreeceDiscode(str) {
        str = str.replace(/Α/g, 'Α');
        str= str.replace(/&Mu;/g, 'Μ');
        str = str.replace(/&Nu;/g, 'Ν');
        str = str.replace(/&Xi;/g, 'Ν');
        str = str.replace(/&Omicron;/g, 'Ο');
        str = str.replace(/&Pi;/g, 'Π');
        str = str.replace(/&Rho;/g, 'Ρ');
        str = str.replace(/&Sigma;/g, 'Σ');
        str = str.replace(/&Tau;/g, 'Τ');
        str = str.replace(/&Upsilon;/g, 'Υ');
        str = str.replace(/&Phi;/g, 'Φ');
        str = str.replace(/&Chi;/g, 'Χ');
        str = str.replace(/&Psi;/g, 'Ψ');
        str = str.replace(/&Omega;/g, 'Ω');

        str = str.replace(/&alpha;/g, 'α');
        str = str.replace(/&beta;/g, 'β');
        str = str.replace(/&gamma;/g, 'γ');
        str = str.replace(/&delta;/g, 'δ');
        str = str.replace(/&epsilon;/g, 'ε');
        str = str.replace(/&zeta;/g, 'ζ');
        str = str.replace(/&eta;/g, 'η');
        str = str.replace(/&theta;/g, 'θ');= str.replace(/&middot;/g, '·');
        return str;
    }

//

    function strcharacterDiscode(str) {
        // 加入常用解析
        str = str.replace(/&nbsp;/g, ' ');
        str = str.replace(/&quot;/g, "'");
        str = str.replace(/&amp;/g, '&');
        // str = str.replace(/&lt;/g, '‹');
        // str = str.replace(/&gt;/g, '›');

        str = str.replace(/&lt;/g, '<');
        str = str.replace(/&gt;/g, '>');
        str = str.replace(/&#8226;/g, '•');

        


    = str.replace(/&ensp;/g, '');
        str = str.replace(/&emsp;/g, '');
        str = str.replace(/&thinsp;/g, '');
        str = str.replace(/&zwnj;/g, '');
        str = str.replace(/&zwj;/g, '');
        str = str.replace(/&lrm;/g, '');
        str = str.replace(/&rlm;/g, '');
        str = str.replace(/&ndash;/g, '–');
        str = str.replace(/&mdash;/g, '—');
        str = str.replace(/&lsquo;/g, '‘');
        str = str.replace(/&rsquo;/g, '’');
        str = str.replace(/&sbquo;/g, '‚');
        str = str.replace(/&ldquo;/g, '“');
        str = str.replace(/&rdquo;/g, '”');
        str = str.replace(/&bdquo;/g, '„');
        str = str.replace(/&dagger;/g, '†');
        str = str.replace(/&Dagger;/g, '‡');
        str = str.replace(/&bull;/g, '•');
        str = str.replace(/&hellip;/g, '…');
        str = str.replace(/&permil;/g, '‰');
        str = str.replace(/&prime;/g, '′');
        str 


= str.replace(/&diams;/g, '♦');
        str = str.replace(/&#39;/g, '\'');
        str = str.replace(/&nbsp;/g, ' ');
        str = str.replace(/&amp;nbsp;/g, ' ');
        return str;
    }

    function strMoreDiscode(str) {
        str = str.replace(/\r\n/g, "");
        str = str.replace(/\n/g, "");

        str = str.replace(/code/g, "wxxxcode-style");
        return str;
    }

    function strDiscode(str) {
        str = strNumDiscode(str);
        str = strGreeceDiscode(str);
        str = strcharacterDiscode(str);
        str = strOtherDiscode(str);
        str = strMoreDiscode(str);
        return str;
    }
    function urlToHttpUrl(url, rep) {

        var patt1 = new RegExp("^//");
        var result = patt1.test(url);
        if (result) {
            url = rep + ":" + url;
        }
        return url;
    }

 

Guess you like

Origin www.cnblogs.com/chengmi/p/11249263.html