From: Alan Date: Thu, 24 Mar 2022 08:34:11 +0000 (+0800) Subject: fix bullet issues with ms paste X-Git-Url: http://git.roojs.org/?p=roojs1;a=commitdiff_plain;h=496be84c167be542ac1f25ee37edf832b0438999 fix bullet issues with ms paste --- diff --git a/Roo/htmleditor/FilterWord.js b/Roo/htmleditor/FilterWord.js index 20849ad8f6..682d2e26b4 100644 --- a/Roo/htmleditor/FilterWord.js +++ b/Roo/htmleditor/FilterWord.js @@ -14,7 +14,7 @@ Roo.htmleditor.FilterWord = function(cfg) // no need to apply config. this.replaceDocBullets(cfg.node); - this.walk(cfg.node); + // this.walk(cfg.node); } @@ -125,7 +125,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, styleToObject: function(node) { - var styles = node.getAttribute("style").split(";"); + var styles = (node.getAttribute("style") || '').split(";"); var ret = {}; Roo.each(styles, function(s) { if (!s.match(/:/)) { @@ -142,10 +142,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, replaceDocBullets : function(doc) { + // this is a bit odd - but it appears some indents use ql-indent-1 + + var listpara = doc.getElementsByClassName('ql-indent-1'); + while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); + } + var listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); - //code } }, @@ -161,7 +167,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, ns = ns.nextSibling; continue; } - if (!ns.className.match(/MsoListParagraph/i)) { + if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } items.push(ns); @@ -174,17 +180,37 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; items.forEach(function(n) { - parent.removeChild(n); + //Roo.log("got innertHMLT=" + n.innerHTML); + var spans = n.getElementsByTagName('span'); - if (!spans.length || !n.isEqualNode(spans.item(0).parentNode)) { + if (!spans.length) { + //Roo.log("No spans found"); + + parent.removeChild(n); return; // skip it... } + + + + var style = {}; + for(var i = 0; i < spans.length; i++) { - var style = this.styleToObject(n); + style = this.styleToObject(spans[i]); + if (typeof(style['mso-list']) == 'undefined') { + continue; + } + + spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. + break; + } + //Roo.log("NOW GOT innertHMLT=" + n.innerHTML); + style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { - return; // skip it. + //Roo.log("parent is missing level"); + parent.removeChild(n); + return; } - n.removeChild(spans.item(0)); // remove the fake bullet. + var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1; if (nlvl > lvl) { //new indent @@ -196,12 +222,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; + nli.innerHTML = n.innerHTML; + //Roo.log("innerHTML = " + n.innerHTML); + parent.removeChild(n); + // copy children of p into nli - while(n.firstChild) { + /*while(n.firstChild) { var fc = n.firstChild; n.removeChild(fc); nli.appendChild(fc); - } + }*/ },this); diff --git a/roojs-all.js b/roojs-all.js index 8b3c3bbc95..bca7579563 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1924,16 +1924,17 @@ Roo.htmleditor.FilterTableWidth=function(A){this.tag=['TABLE','TD','TR','TH','TH }if(A.hasAttribute("style")){var B=A.getAttribute("style").split(";");var C=[];Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^\s*(width|min-width)\s*$/)){return;}C.push(s);});A.setAttribute("style",C.length?C.join(';'):''); if(!C.length){A.removeAttribute('style');}}return true;}}); // Roo/htmleditor/FilterWord.js -Roo.htmleditor.FilterWord=function(A){this.replaceDocBullets(A.node);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterWord,Roo.htmleditor.Filter,{tag:true,replaceTag:function(A){if(A.nodeName=='SPAN'&&!A.hasAttributes()&&A.childNodes.length==1&&A.firstChild.nodeName=="#text"){var B=A.firstChild; +Roo.htmleditor.FilterWord=function(A){this.replaceDocBullets(A.node);};Roo.extend(Roo.htmleditor.FilterWord,Roo.htmleditor.Filter,{tag:true,replaceTag:function(A){if(A.nodeName=='SPAN'&&!A.hasAttributes()&&A.childNodes.length==1&&A.firstChild.nodeName=="#text"){var B=A.firstChild; A.removeChild(B);if(A.getAttribute('lang')!='zh-CN'){A.parentNode.insertBefore(A.ownerDocument.createTextNode(" "),A);}A.parentNode.insertBefore(B,A);if(A.getAttribute('lang')!='zh-CN'){A.parentNode.insertBefore(A.ownerDocument.createTextNode(" "),A);}A.parentNode.removeChild(A); return false;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)){A.parentNode.removeChild(A);return false;}if(A.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)){while(A.childNodes.length){var cn=A.childNodes[0]; A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replaceTag(cn);}}A.parentNode.removeChild(A);return false;}if(A.className.length){var cn=A.className.split(/\W+/);var C=[];Roo.each(cn,function(F){if(F.match(/Mso[a-zA-Z]+/)){return; }C.push(F);});A.className=C.length?C.join(' '):'';if(!C.length){A.removeAttribute("class");}}if(A.hasAttribute("lang")){A.removeAttribute("lang");}if(A.hasAttribute("style")){var D=A.getAttribute("style").split(";");var E=[];Roo.each(D,function(s){if(!s.match(/:/)){return; -}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}E.push(s);});A.setAttribute("style",E.length?E.join(';'):'');if(!E.length){A.removeAttribute('style');}}return true;},styleToObject:function(A){var B=A.getAttribute("style").split(";"); -var C={};Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");C[kv[0]]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraph');while(B.length){this.replaceDocBullet(B.item(0));}},replaceDocBullet:function(p){var ns=p,A=p.parentNode,B=A.ownerDocument,C=[]; -while(ns){if(ns.nodeType!=1){ns=ns.nextSibling;continue;}if(!ns.className.match(/MsoListParagraph/i)){break;}C.push(ns);ns=ns.nextSibling;}var ul=A.ownerDocument.createElement('ul');A.insertBefore(ul,p);var D=0;var E=[ul];var F=false;C.forEach(function(n){A.removeChild(n); -var G=n.getElementsByTagName('span');if(!G.length||!n.isEqualNode(G.item(0).parentNode)){return;}var H=this.styleToObject(n);if(typeof(H['mso-list'])=='undefined'){return;}n.removeChild(G.item(0));var I=(H['mso-list'].split(' ')[1].replace(/level/,'')*1)-1; -if(I>D){var J=B.createElement('ul');F.appendChild(J);E[I]=J;}D=I;var K=E[I].appendChild(B.createElement('li'));F=K;while(n.firstChild){var fc=n.firstChild;n.removeChild(fc);K.appendChild(fc);}},this);}}); +}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}E.push(s);});A.setAttribute("style",E.length?E.join(';'):'');if(!E.length){A.removeAttribute('style');}}return true;},styleToObject:function(A){var B=(A.getAttribute("style")||'').split(";"); +var C={};Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");C[kv[0]]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('ql-indent-1');while(B.length){this.replaceDocBullet(B.item(0));}var B=A.getElementsByClassName('MsoListParagraph'); +while(B.length){this.replaceDocBullet(B.item(0));}},replaceDocBullet:function(p){var ns=p,A=p.parentNode,B=A.ownerDocument,C=[];while(ns){if(ns.nodeType!=1){ns=ns.nextSibling;continue;}if(!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)){break;}C.push(ns); +ns=ns.nextSibling;}var ul=A.ownerDocument.createElement('ul');A.insertBefore(ul,p);var D=0;var E=[ul];var F=false;C.forEach(function(n){var G=n.getElementsByTagName('span');if(!G.length){A.removeChild(n);return;}var H={};for(var i=0;iD){var J=B.createElement('ul'); +F.appendChild(J);E[I]=J;}D=I;var K=E[I].appendChild(B.createElement('li'));F=K;K.innerHTML=n.innerHTML;A.removeChild(n);},this);}}); // Roo/htmleditor/FilterStyleToTag.js Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I:['fontStyle','italic'],SUP:['verticalAlign','super'],SUB:['verticalAlign','sub']};Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterStyleToTag,Roo.htmleditor.Filter,{tag:true,tags:false,replaceTag:function(A){if(A.getAttribute("style")===null){return true; }var B=[];for(var k in this.tags){if(A.style[this.tags[k][0]]==this.tags[k][1]){B.push(k);A.style.removeProperty(this.tags[k][0]);}}if(!B.length){return true;}var cn=Array.from(A.childNodes);var nn=A;Roo.each(B,function(t){var nc=A.ownerDocument.createElement(t); diff --git a/roojs-debug.js b/roojs-debug.js index 56f81942e0..3a57b8d57a 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -46074,7 +46074,7 @@ Roo.htmleditor.FilterWord = function(cfg) // no need to apply config. this.replaceDocBullets(cfg.node); - this.walk(cfg.node); + // this.walk(cfg.node); } @@ -46185,7 +46185,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, styleToObject: function(node) { - var styles = node.getAttribute("style").split(";"); + var styles = (node.getAttribute("style") || '').split(";"); var ret = {}; Roo.each(styles, function(s) { if (!s.match(/:/)) { @@ -46202,10 +46202,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, replaceDocBullets : function(doc) { + // this is a bit odd - but it appears some indents use ql-indent-1 + + var listpara = doc.getElementsByClassName('ql-indent-1'); + while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); + } + var listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); - //code } }, @@ -46221,7 +46227,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, ns = ns.nextSibling; continue; } - if (!ns.className.match(/MsoListParagraph/i)) { + if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } items.push(ns); @@ -46234,17 +46240,37 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; items.forEach(function(n) { - parent.removeChild(n); + //Roo.log("got innertHMLT=" + n.innerHTML); + var spans = n.getElementsByTagName('span'); - if (!spans.length || !n.isEqualNode(spans.item(0).parentNode)) { + if (!spans.length) { + //Roo.log("No spans found"); + + parent.removeChild(n); return; // skip it... } + + - var style = this.styleToObject(n); + var style = {}; + for(var i = 0; i < spans.length; i++) { + + style = this.styleToObject(spans[i]); + if (typeof(style['mso-list']) == 'undefined') { + continue; + } + + spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. + break; + } + //Roo.log("NOW GOT innertHMLT=" + n.innerHTML); + style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { - return; // skip it. + //Roo.log("parent is missing level"); + parent.removeChild(n); + return; } - n.removeChild(spans.item(0)); // remove the fake bullet. + var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1; if (nlvl > lvl) { //new indent @@ -46256,12 +46282,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; + nli.innerHTML = n.innerHTML; + //Roo.log("innerHTML = " + n.innerHTML); + parent.removeChild(n); + // copy children of p into nli - while(n.firstChild) { + /*while(n.firstChild) { var fc = n.firstChild; n.removeChild(fc); nli.appendChild(fc); - } + }*/ },this); diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index d0a33a9460..ead11143ef 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -21582,7 +21582,7 @@ Roo.htmleditor.FilterWord = function(cfg) // no need to apply config. this.replaceDocBullets(cfg.node); - this.walk(cfg.node); + // this.walk(cfg.node); } @@ -21693,7 +21693,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, styleToObject: function(node) { - var styles = node.getAttribute("style").split(";"); + var styles = (node.getAttribute("style") || '').split(";"); var ret = {}; Roo.each(styles, function(s) { if (!s.match(/:/)) { @@ -21710,10 +21710,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, replaceDocBullets : function(doc) { + // this is a bit odd - but it appears some indents use ql-indent-1 + + var listpara = doc.getElementsByClassName('ql-indent-1'); + while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); + } + var listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); - //code } }, @@ -21729,7 +21735,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, ns = ns.nextSibling; continue; } - if (!ns.className.match(/MsoListParagraph/i)) { + if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } items.push(ns); @@ -21742,17 +21748,37 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; items.forEach(function(n) { - parent.removeChild(n); + //Roo.log("got innertHMLT=" + n.innerHTML); + var spans = n.getElementsByTagName('span'); - if (!spans.length || !n.isEqualNode(spans.item(0).parentNode)) { + if (!spans.length) { + //Roo.log("No spans found"); + + parent.removeChild(n); return; // skip it... } + + - var style = this.styleToObject(n); + var style = {}; + for(var i = 0; i < spans.length; i++) { + + style = this.styleToObject(spans[i]); + if (typeof(style['mso-list']) == 'undefined') { + continue; + } + + spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. + break; + } + //Roo.log("NOW GOT innertHMLT=" + n.innerHTML); + style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { - return; // skip it. + //Roo.log("parent is missing level"); + parent.removeChild(n); + return; } - n.removeChild(spans.item(0)); // remove the fake bullet. + var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1; if (nlvl > lvl) { //new indent @@ -21764,12 +21790,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; + nli.innerHTML = n.innerHTML; + //Roo.log("innerHTML = " + n.innerHTML); + parent.removeChild(n); + // copy children of p into nli - while(n.firstChild) { + /*while(n.firstChild) { var fc = n.firstChild; n.removeChild(fc); nli.appendChild(fc); - } + }*/ },this); diff --git a/roojs-ui.js b/roojs-ui.js index 17b7b9cf80..7605603234 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -978,16 +978,17 @@ Roo.htmleditor.FilterTableWidth=function(A){this.tag=['TABLE','TD','TR','TH','TH }if(A.hasAttribute("style")){var B=A.getAttribute("style").split(";");var C=[];Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");if(kv[0].match(/^\s*(width|min-width)\s*$/)){return;}C.push(s);});A.setAttribute("style",C.length?C.join(';'):''); if(!C.length){A.removeAttribute('style');}}return true;}}); // Roo/htmleditor/FilterWord.js -Roo.htmleditor.FilterWord=function(A){this.replaceDocBullets(A.node);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterWord,Roo.htmleditor.Filter,{tag:true,replaceTag:function(A){if(A.nodeName=='SPAN'&&!A.hasAttributes()&&A.childNodes.length==1&&A.firstChild.nodeName=="#text"){var B=A.firstChild; +Roo.htmleditor.FilterWord=function(A){this.replaceDocBullets(A.node);};Roo.extend(Roo.htmleditor.FilterWord,Roo.htmleditor.Filter,{tag:true,replaceTag:function(A){if(A.nodeName=='SPAN'&&!A.hasAttributes()&&A.childNodes.length==1&&A.firstChild.nodeName=="#text"){var B=A.firstChild; A.removeChild(B);if(A.getAttribute('lang')!='zh-CN'){A.parentNode.insertBefore(A.ownerDocument.createTextNode(" "),A);}A.parentNode.insertBefore(B,A);if(A.getAttribute('lang')!='zh-CN'){A.parentNode.insertBefore(A.ownerDocument.createTextNode(" "),A);}A.parentNode.removeChild(A); return false;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)){A.parentNode.removeChild(A);return false;}if(A.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)){while(A.childNodes.length){var cn=A.childNodes[0]; A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replaceTag(cn);}}A.parentNode.removeChild(A);return false;}if(A.className.length){var cn=A.className.split(/\W+/);var C=[];Roo.each(cn,function(F){if(F.match(/Mso[a-zA-Z]+/)){return; }C.push(F);});A.className=C.length?C.join(' '):'';if(!C.length){A.removeAttribute("class");}}if(A.hasAttribute("lang")){A.removeAttribute("lang");}if(A.hasAttribute("style")){var D=A.getAttribute("style").split(";");var E=[];Roo.each(D,function(s){if(!s.match(/:/)){return; -}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}E.push(s);});A.setAttribute("style",E.length?E.join(';'):'');if(!E.length){A.removeAttribute('style');}}return true;},styleToObject:function(A){var B=A.getAttribute("style").split(";"); -var C={};Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");C[kv[0]]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraph');while(B.length){this.replaceDocBullet(B.item(0));}},replaceDocBullet:function(p){var ns=p,A=p.parentNode,B=A.ownerDocument,C=[]; -while(ns){if(ns.nodeType!=1){ns=ns.nextSibling;continue;}if(!ns.className.match(/MsoListParagraph/i)){break;}C.push(ns);ns=ns.nextSibling;}var ul=A.ownerDocument.createElement('ul');A.insertBefore(ul,p);var D=0;var E=[ul];var F=false;C.forEach(function(n){A.removeChild(n); -var G=n.getElementsByTagName('span');if(!G.length||!n.isEqualNode(G.item(0).parentNode)){return;}var H=this.styleToObject(n);if(typeof(H['mso-list'])=='undefined'){return;}n.removeChild(G.item(0));var I=(H['mso-list'].split(' ')[1].replace(/level/,'')*1)-1; -if(I>D){var J=B.createElement('ul');F.appendChild(J);E[I]=J;}D=I;var K=E[I].appendChild(B.createElement('li'));F=K;while(n.firstChild){var fc=n.firstChild;n.removeChild(fc);K.appendChild(fc);}},this);}}); +}var kv=s.split(":");if(kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)){return;}E.push(s);});A.setAttribute("style",E.length?E.join(';'):'');if(!E.length){A.removeAttribute('style');}}return true;},styleToObject:function(A){var B=(A.getAttribute("style")||'').split(";"); +var C={};Roo.each(B,function(s){if(!s.match(/:/)){return;}var kv=s.split(":");C[kv[0]]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('ql-indent-1');while(B.length){this.replaceDocBullet(B.item(0));}var B=A.getElementsByClassName('MsoListParagraph'); +while(B.length){this.replaceDocBullet(B.item(0));}},replaceDocBullet:function(p){var ns=p,A=p.parentNode,B=A.ownerDocument,C=[];while(ns){if(ns.nodeType!=1){ns=ns.nextSibling;continue;}if(!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)){break;}C.push(ns); +ns=ns.nextSibling;}var ul=A.ownerDocument.createElement('ul');A.insertBefore(ul,p);var D=0;var E=[ul];var F=false;C.forEach(function(n){var G=n.getElementsByTagName('span');if(!G.length){A.removeChild(n);return;}var H={};for(var i=0;iD){var J=B.createElement('ul'); +F.appendChild(J);E[I]=J;}D=I;var K=E[I].appendChild(B.createElement('li'));F=K;K.innerHTML=n.innerHTML;A.removeChild(n);},this);}}); // Roo/htmleditor/FilterStyleToTag.js Roo.htmleditor.FilterStyleToTag=function(A){this.tags={B:['fontWeight','bold'],I:['fontStyle','italic'],SUP:['verticalAlign','super'],SUB:['verticalAlign','sub']};Roo.apply(this,A);this.walk(A.node);};Roo.extend(Roo.htmleditor.FilterStyleToTag,Roo.htmleditor.Filter,{tag:true,tags:false,replaceTag:function(A){if(A.getAttribute("style")===null){return true; }var B=[];for(var k in this.tags){if(A.style[this.tags[k][0]]==this.tags[k][1]){B.push(k);A.style.removeProperty(this.tags[k][0]);}}if(!B.length){return true;}var cn=Array.from(A.childNodes);var nn=A;Roo.each(B,function(t){var nc=A.ownerDocument.createElement(t);