From 2942ea304243898c835050214076e1f83d73f18a Mon Sep 17 00:00:00 2001 From: Alan Date: Mon, 27 Jun 2022 15:45:14 +0800 Subject: [PATCH] fix bullet point issue - with pasting word documents --- docs/src/Roo_htmleditor_BlockTd.js.html | 1 - docs/src/Roo_htmleditor_FilterWord.js.html | 42 ++++++++++++++----- roojs-all.js | 9 +++-- roojs-bootstrap-debug.js | 47 ++++++++++++++++------ roojs-bootstrap.js | 9 +++-- roojs-debug.js | 47 ++++++++++++++++------ roojs-ui-debug.js | 47 ++++++++++++++++------ roojs-ui.js | 9 +++-- 8 files changed, 149 insertions(+), 62 deletions(-) diff --git a/docs/src/Roo_htmleditor_BlockTd.js.html b/docs/src/Roo_htmleditor_BlockTd.js.html index 6155c949cd..843b24990b 100644 --- a/docs/src/Roo_htmleditor_BlockTd.js.html +++ b/docs/src/Roo_htmleditor_BlockTd.js.html @@ -542,7 +542,6 @@ for(var r = cd.row; r < cd.row + cd.rowspan; r++) { - for(var c = cd.col; c < cd.col + cd.colspan; c++) { if (r == cd.row && c == cd.col) { this.node.removeAttribute('rowspan'); diff --git a/docs/src/Roo_htmleditor_FilterWord.js.html b/docs/src/Roo_htmleditor_FilterWord.js.html index 768787a305..e4d5feb5b0 100644 --- a/docs/src/Roo_htmleditor_FilterWord.js.html +++ b/docs/src/Roo_htmleditor_FilterWord.js.html @@ -144,7 +144,7 @@ replaceDocBullets : function(doc) { // this is a bit odd - but it appears some indents use ql-indent-1 - //Roo.log(doc.innerHTML); + //Roo.log(doc.innerHTML); var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst'); for( var i = 0; i < listpara.length; i ++) { @@ -164,11 +164,14 @@ } listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); } }, + + replaceDocBullet : function(p) { // gather all the siblings. @@ -186,10 +189,29 @@ if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); + if (!spans.length) { + break; + } + var has_list = false; + for(var i = 0; i < spans.length; i++) { + if (spans[i].getAttribute('style').match(/mso-list/)) { + has_list = true; + break; + } + } + if (!has_list) { + break; + } + + items.push(ns); ns = ns.nextSibling; } - + if (!items.length) { + ns.className = ""; + return; + } var ul = parent.ownerDocument.createElement('ul'); // what about number lists... parent.insertBefore(ul, p); @@ -197,6 +219,7 @@ var stack = [ ul ]; var last_li = false; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); @@ -205,6 +228,8 @@ //Roo.log("No spans found"); parent.removeChild(n); + + return; // skip it... } @@ -225,14 +250,16 @@ style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { //Roo.log("parent is missing level"); + + parent.removeChild(n); + return; } var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1 ; - if (nlvl > lvl) { //new indent var nul = doc.createElement('ul'); // what about number lists... @@ -252,15 +279,10 @@ //Roo.log("innerHTML = " + n.innerHTML); parent.removeChild(n); - // copy children of p into nli - /*while(n.firstChild) { - var fc = n.firstChild; - n.removeChild(fc); - nli.appendChild(fc); - }*/ - },this); + + },this); diff --git a/roojs-all.js b/roojs-all.js index 39a3e49f52..c7af40c602 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1932,10 +1932,11 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac }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].trim()]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');for(var i=0;iD){var K=B.createElement('ul'); -if(!F){F=B.createElement('li');E[D].appendChild(F);}F.appendChild(K);E[J]=K;}D=J;var L=E[J].appendChild(B.createElement('li'));F=L;L.innerHTML=n.innerHTML;A.removeChild(n);},this);}}); +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;}var D=ns.getElementsByTagName('span'); +if(!D.length){break;}var E=false;for(var i=0;iF){var M=B.createElement('ul');if(!H){H=B.createElement('li');G[F].appendChild(H);}H.appendChild(M); +G[L]=M;}F=L;var N=G[L].appendChild(B.createElement('li'));H=N;N.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-bootstrap-debug.js b/roojs-bootstrap-debug.js index ea98f39293..f3b9f0c03f 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -26597,7 +26597,7 @@ 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 - //Roo.log(doc.innerHTML); + //Roo.log(doc.innerHTML); var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst'); for( var i = 0; i < listpara.length; i ++) { @@ -26617,11 +26617,14 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); } }, + + replaceDocBullet : function(p) { // gather all the siblings. @@ -26639,10 +26642,29 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); + if (!spans.length) { + break; + } + var has_list = false; + for(var i = 0; i < spans.length; i++) { + if (spans[i].getAttribute('style').match(/mso-list/)) { + has_list = true; + break; + } + } + if (!has_list) { + break; + } + + items.push(ns); ns = ns.nextSibling; } - + if (!items.length) { + ns.className = ""; + return; + } var ul = parent.ownerDocument.createElement('ul'); // what about number lists... parent.insertBefore(ul, p); @@ -26650,14 +26672,17 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); var spans = n.getElementsByTagName('span'); if (!spans.length) { //Roo.log("No spans found"); - + parent.removeChild(n); + + return; // skip it... } @@ -26678,14 +26703,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { //Roo.log("parent is missing level"); + + parent.removeChild(n); + return; } var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1 ; - - + if (nlvl > lvl) { //new indent var nul = doc.createElement('ul'); // what about number lists... @@ -26705,12 +26732,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, //Roo.log("innerHTML = " + n.innerHTML); parent.removeChild(n); - // copy children of p into nli - /*while(n.firstChild) { - var fc = n.firstChild; - n.removeChild(fc); - nli.appendChild(fc); - }*/ + },this); @@ -28596,8 +28618,7 @@ Roo.extend(Roo.htmleditor.BlockTd, Roo.htmleditor.Block, { this.colspan = 1; for(var r = cd.row; r < cd.row + cd.rowspan; r++) { - - + for(var c = cd.col; c < cd.col + cd.colspan; c++) { if (r == cd.row && c == cd.col) { diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index 6e4e3eefeb..9957d3cb61 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1151,10 +1151,11 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac }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].trim()]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');for(var i=0;iD){var K=B.createElement('ul'); -if(!F){F=B.createElement('li');E[D].appendChild(F);}F.appendChild(K);E[J]=K;}D=J;var L=E[J].appendChild(B.createElement('li'));F=L;L.innerHTML=n.innerHTML;A.removeChild(n);},this);}}); +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;}var D=ns.getElementsByTagName('span'); +if(!D.length){break;}var E=false;for(var i=0;iF){var M=B.createElement('ul');if(!H){H=B.createElement('li');G[F].appendChild(H);}H.appendChild(M); +G[L]=M;}F=L;var N=G[L].appendChild(B.createElement('li'));H=N;N.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 779fa0189f..92a548dc29 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -46211,7 +46211,7 @@ 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 - //Roo.log(doc.innerHTML); + //Roo.log(doc.innerHTML); var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst'); for( var i = 0; i < listpara.length; i ++) { @@ -46231,11 +46231,14 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); } }, + + replaceDocBullet : function(p) { // gather all the siblings. @@ -46253,10 +46256,29 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); + if (!spans.length) { + break; + } + var has_list = false; + for(var i = 0; i < spans.length; i++) { + if (spans[i].getAttribute('style').match(/mso-list/)) { + has_list = true; + break; + } + } + if (!has_list) { + break; + } + + items.push(ns); ns = ns.nextSibling; } - + if (!items.length) { + ns.className = ""; + return; + } var ul = parent.ownerDocument.createElement('ul'); // what about number lists... parent.insertBefore(ul, p); @@ -46264,14 +46286,17 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); var spans = n.getElementsByTagName('span'); if (!spans.length) { //Roo.log("No spans found"); - + parent.removeChild(n); + + return; // skip it... } @@ -46292,14 +46317,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { //Roo.log("parent is missing level"); + + parent.removeChild(n); + return; } var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1 ; - - + if (nlvl > lvl) { //new indent var nul = doc.createElement('ul'); // what about number lists... @@ -46319,12 +46346,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, //Roo.log("innerHTML = " + n.innerHTML); parent.removeChild(n); - // copy children of p into nli - /*while(n.firstChild) { - var fc = n.firstChild; - n.removeChild(fc); - nli.appendChild(fc); - }*/ + },this); @@ -49477,8 +49499,7 @@ Roo.extend(Roo.htmleditor.BlockTd, Roo.htmleditor.Block, { this.colspan = 1; for(var r = cd.row; r < cd.row + cd.rowspan; r++) { - - + for(var c = cd.col; c < cd.col + cd.colspan; c++) { if (r == cd.row && c == cd.col) { diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 6623fbfdb0..b41b64c00c 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -21719,7 +21719,7 @@ 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 - //Roo.log(doc.innerHTML); + //Roo.log(doc.innerHTML); var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst'); for( var i = 0; i < listpara.length; i ++) { @@ -21739,11 +21739,14 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } listpara = doc.getElementsByClassName('MsoListParagraph'); while(listpara.length) { + this.replaceDocBullet(listpara.item(0)); } }, + + replaceDocBullet : function(p) { // gather all the siblings. @@ -21761,10 +21764,29 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); + if (!spans.length) { + break; + } + var has_list = false; + for(var i = 0; i < spans.length; i++) { + if (spans[i].getAttribute('style').match(/mso-list/)) { + has_list = true; + break; + } + } + if (!has_list) { + break; + } + + items.push(ns); ns = ns.nextSibling; } - + if (!items.length) { + ns.className = ""; + return; + } var ul = parent.ownerDocument.createElement('ul'); // what about number lists... parent.insertBefore(ul, p); @@ -21772,14 +21794,17 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); var spans = n.getElementsByTagName('span'); if (!spans.length) { //Roo.log("No spans found"); - + parent.removeChild(n); + + return; // skip it... } @@ -21800,14 +21825,16 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, style = this.styleToObject(n); // mo-list is from the parent node. if (typeof(style['mso-list']) == 'undefined') { //Roo.log("parent is missing level"); + + parent.removeChild(n); + return; } var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1 ; - - + if (nlvl > lvl) { //new indent var nul = doc.createElement('ul'); // what about number lists... @@ -21827,12 +21854,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, //Roo.log("innerHTML = " + n.innerHTML); parent.removeChild(n); - // copy children of p into nli - /*while(n.firstChild) { - var fc = n.firstChild; - n.removeChild(fc); - nli.appendChild(fc); - }*/ + },this); @@ -24985,8 +25007,7 @@ Roo.extend(Roo.htmleditor.BlockTd, Roo.htmleditor.Block, { this.colspan = 1; for(var r = cd.row; r < cd.row + cd.rowspan; r++) { - - + for(var c = cd.col; c < cd.col + cd.colspan; c++) { if (r == cd.row && c == cd.col) { diff --git a/roojs-ui.js b/roojs-ui.js index 40ce72d195..7456c80092 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -986,10 +986,11 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac }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].trim()]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');for(var i=0;iD){var K=B.createElement('ul'); -if(!F){F=B.createElement('li');E[D].appendChild(F);}F.appendChild(K);E[J]=K;}D=J;var L=E[J].appendChild(B.createElement('li'));F=L;L.innerHTML=n.innerHTML;A.removeChild(n);},this);}}); +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;}var D=ns.getElementsByTagName('span'); +if(!D.length){break;}var E=false;for(var i=0;iF){var M=B.createElement('ul');if(!H){H=B.createElement('li');G[F].appendChild(H);}H.appendChild(M); +G[L]=M;}F=L;var N=G[L].appendChild(B.createElement('li'));H=N;N.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); -- 2.39.2