去除UEditorField中自動(dòng)生成的p標(biāo)簽

在項(xiàng)目中,一個(gè)文章修改模塊用到ueditor,

但是每次修改完文章點(diǎn)擊保存后,ueditor就會(huì)自動(dòng)套上一個(gè)p標(biāo)簽,

多次修改后,ueditor就會(huì)不斷的在外層套一個(gè)p標(biāo)簽,以至于明明沒有修改,但是它卻不斷的換行。

方法一:(嘗試失敗)

不允許修改ueditor默認(rèn)源碼的配置,只能選擇覆蓋掉。

<!--覆蓋ueditor自動(dòng)生成的p標(biāo)簽-->

var?editor?=?UE.getEditor('editor',{?????

enterTag?:'br'??

});??

方法二:(找到文本模塊中DajngoUEditor文件中的ueditor.all.js,嘗試失?。?/p>

將自動(dòng)生成p標(biāo)簽的內(nèi)容全部注釋掉

//進(jìn)入編輯器的li要套p標(biāo)簽

? ? 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 ? ' ' : '
')

//? ? ? ? ? ? }

//去掉末尾的空白

//? ? ? ? ? ? var p = li.firstChild();

//? ? ? ? ? ? var lastChild = p.lastChild();

//? ? ? ? ? ? if(lastChild && lastChild.type == 'text' && /^\s*$/.test(lastChild.data)){

//? ? ? ? ? ? ? ? p.removeChild(lastChild)

//? ? ? ? ? ? }

//? ? ? ? });


方法三:??加“|safe”

感謝原出處

http://www.itdecent.cn/p/5584c65b675b

之前:

<div class="jieshao">

? ? <span class="jieshao_banner">商品介紹</span>

? ? <div class="goods_detailcontent">{{goods.gdetailcontent}}</div>

</div>


上圖的文字自動(dòng)追加了<p>標(biāo)簽解決方法是在前端引用時(shí)加入|safe:

之后:

<div class="goods_detailcontent">{{goods.gdetailcontent |safe}}</div>


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容