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 ? ' ' : '<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(/∀/g, '∀'); str = str.replace(/∂/g, '∂'); str = str.replace(/&exists;/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, '∑'); 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, '∧'); 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, '≅'); 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, '⊄'); 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(/Μ/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, 'Τ'); 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, 'β'); 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.replace(/·/g, '·'); return str; } // function strcharacterDiscode(str) { // 加入常用解析 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, '>'); str = str.replace(/•/g, '•'); = 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, ''); 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, '”'); 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, '′'); str = str.replace(/♦/g, '♦'); str = str.replace(/'/g, '\''); str = str.replace(/ /g, ' '); str = str.replace(/&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; }