From 6387d7ef9465bff1ef6353e264016e71df096e83 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 29 Jun 2022 10:52:49 +0800 Subject: [PATCH] Fix #7284 - more issues with bullet point detection --- Roo/htmleditor/FilterWord.js | 41 +++++++++++++++++++++++++----------- roojs-all.js | 13 ++++++------ roojs-bootstrap-debug.js | 41 +++++++++++++++++++++++++----------- roojs-bootstrap.js | 13 ++++++------ roojs-debug.js | 41 +++++++++++++++++++++++++----------- roojs-ui-debug.js | 41 +++++++++++++++++++++++++----------- roojs-ui.js | 13 ++++++------ 7 files changed, 137 insertions(+), 66 deletions(-) diff --git a/Roo/htmleditor/FilterWord.js b/Roo/htmleditor/FilterWord.js index d3d6cc411d..a9fad68e12 100644 --- a/Roo/htmleditor/FilterWord.js +++ b/Roo/htmleditor/FilterWord.js @@ -139,12 +139,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, }); return ret; }, - - + 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 ++) { @@ -153,11 +152,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, // this is a bit hacky - we had one word document where h2 had a miso-list attribute. var htwo = doc.getElementsByTagName('h2'); for( var i = 0; i < htwo.length; i ++) { - if (htwo.item(i).getAttribute('style').match(/mso-list:/)) { + if (htwo.item(i).hasAttribute('style') && htwo.item(i).getAttribute('style').match(/mso-list:/)) { htwo.item(i).className = "MsoListParagraph"; } } - + listpara = doc.getElementsByClassName('MsoNormal'); + while(listpara.length) { + if (listpara.item(0).hasAttribute('style') && listpara.item(0).getAttribute('style').match(/mso-list:/)) { + listpara.item(0).className = "MsoListParagraph"; + } else { + listpara.item(0).className = "MsoNormalx"; + } + } listpara = doc.getElementsByClassName('ql-indent-1'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -189,6 +195,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + if (ns.getAttribute('style').match(/mso-list/)) { + items.push(ns); + ns = ns.nextSibling; + has_list = true; + continue; + } var spans = ns.getElementsByTagName('span'); if (!spans.length) { break; @@ -203,10 +215,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!has_list) { break; } - - items.push(ns); ns = ns.nextSibling; + + } if (!items.length) { ns.className = ""; @@ -219,7 +231,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; - + var margin_to_depth = {}; + max_margins = -1; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); @@ -250,15 +264,18 @@ 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 ; - + var margin = style['margin-left']; + if (typeof(margin_to_depth[margin]) == 'undefined') { + max_margins++; + margin_to_depth[margin] = max_margins; + } + nlvl = margin_to_depth[margin] ; if (nlvl > lvl) { //new indent diff --git a/roojs-all.js b/roojs-all.js index 9688489040..9608c7f34e 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1931,12 +1931,13 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac }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].trim()]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');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);}}); +}var C=A.getElementsByTagName('h2');for(var i=0;iF){var N=B.createElement('ul'); +if(!H){H=B.createElement('li');G[F].appendChild(H);}H.appendChild(N);G[nlvl]=N;}F=nlvl;var O=G[nlvl].appendChild(B.createElement('li'));H=O;O.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 2f3c656df7..d46f596c0d 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -26592,12 +26592,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, }); return ret; }, - - + 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 ++) { @@ -26606,11 +26605,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, // this is a bit hacky - we had one word document where h2 had a miso-list attribute. var htwo = doc.getElementsByTagName('h2'); for( var i = 0; i < htwo.length; i ++) { - if (htwo.item(i).getAttribute('style').match(/mso-list:/)) { + if (htwo.item(i).hasAttribute('style') && htwo.item(i).getAttribute('style').match(/mso-list:/)) { htwo.item(i).className = "MsoListParagraph"; } } - + listpara = doc.getElementsByClassName('MsoNormal'); + while(listpara.length) { + if (listpara.item(0).hasAttribute('style') && listpara.item(0).getAttribute('style').match(/mso-list:/)) { + listpara.item(0).className = "MsoListParagraph"; + } else { + listpara.item(0).className = "MsoNormalx"; + } + } listpara = doc.getElementsByClassName('ql-indent-1'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -26642,6 +26648,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + if (ns.getAttribute('style').match(/mso-list/)) { + items.push(ns); + ns = ns.nextSibling; + has_list = true; + continue; + } var spans = ns.getElementsByTagName('span'); if (!spans.length) { break; @@ -26656,10 +26668,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!has_list) { break; } - - items.push(ns); ns = ns.nextSibling; + + } if (!items.length) { ns.className = ""; @@ -26672,7 +26684,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; - + var margin_to_depth = {}; + max_margins = -1; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); @@ -26703,15 +26717,18 @@ 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 ; - + var margin = style['margin-left']; + if (typeof(margin_to_depth[margin]) == 'undefined') { + max_margins++; + margin_to_depth[margin] = max_margins; + } + nlvl = margin_to_depth[margin] ; if (nlvl > lvl) { //new indent diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index 692ae872a1..379f958ac6 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1150,12 +1150,13 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac }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].trim()]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');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);}}); +}var C=A.getElementsByTagName('h2');for(var i=0;iF){var N=B.createElement('ul'); +if(!H){H=B.createElement('li');G[F].appendChild(H);}H.appendChild(N);G[nlvl]=N;}F=nlvl;var O=G[nlvl].appendChild(B.createElement('li'));H=O;O.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 1c1d336198..bbbe6a83de 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -46206,12 +46206,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, }); return ret; }, - - + 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 ++) { @@ -46220,11 +46219,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, // this is a bit hacky - we had one word document where h2 had a miso-list attribute. var htwo = doc.getElementsByTagName('h2'); for( var i = 0; i < htwo.length; i ++) { - if (htwo.item(i).getAttribute('style').match(/mso-list:/)) { + if (htwo.item(i).hasAttribute('style') && htwo.item(i).getAttribute('style').match(/mso-list:/)) { htwo.item(i).className = "MsoListParagraph"; } } - + listpara = doc.getElementsByClassName('MsoNormal'); + while(listpara.length) { + if (listpara.item(0).hasAttribute('style') && listpara.item(0).getAttribute('style').match(/mso-list:/)) { + listpara.item(0).className = "MsoListParagraph"; + } else { + listpara.item(0).className = "MsoNormalx"; + } + } listpara = doc.getElementsByClassName('ql-indent-1'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -46256,6 +46262,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + if (ns.getAttribute('style').match(/mso-list/)) { + items.push(ns); + ns = ns.nextSibling; + has_list = true; + continue; + } var spans = ns.getElementsByTagName('span'); if (!spans.length) { break; @@ -46270,10 +46282,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!has_list) { break; } - - items.push(ns); ns = ns.nextSibling; + + } if (!items.length) { ns.className = ""; @@ -46286,7 +46298,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; - + var margin_to_depth = {}; + max_margins = -1; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); @@ -46317,15 +46331,18 @@ 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 ; - + var margin = style['margin-left']; + if (typeof(margin_to_depth[margin]) == 'undefined') { + max_margins++; + margin_to_depth[margin] = max_margins; + } + nlvl = margin_to_depth[margin] ; if (nlvl > lvl) { //new indent diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index 17bdaa96e1..27bb0524de 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -21714,12 +21714,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, }); return ret; }, - - + 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 ++) { @@ -21728,11 +21727,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, // this is a bit hacky - we had one word document where h2 had a miso-list attribute. var htwo = doc.getElementsByTagName('h2'); for( var i = 0; i < htwo.length; i ++) { - if (htwo.item(i).getAttribute('style').match(/mso-list:/)) { + if (htwo.item(i).hasAttribute('style') && htwo.item(i).getAttribute('style').match(/mso-list:/)) { htwo.item(i).className = "MsoListParagraph"; } } - + listpara = doc.getElementsByClassName('MsoNormal'); + while(listpara.length) { + if (listpara.item(0).hasAttribute('style') && listpara.item(0).getAttribute('style').match(/mso-list:/)) { + listpara.item(0).className = "MsoListParagraph"; + } else { + listpara.item(0).className = "MsoNormalx"; + } + } listpara = doc.getElementsByClassName('ql-indent-1'); while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -21764,6 +21770,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + if (ns.getAttribute('style').match(/mso-list/)) { + items.push(ns); + ns = ns.nextSibling; + has_list = true; + continue; + } var spans = ns.getElementsByTagName('span'); if (!spans.length) { break; @@ -21778,10 +21790,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!has_list) { break; } - - items.push(ns); ns = ns.nextSibling; + + } if (!items.length) { ns.className = ""; @@ -21794,7 +21806,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, var stack = [ ul ]; var last_li = false; - + var margin_to_depth = {}; + max_margins = -1; + items.forEach(function(n, ipos) { //Roo.log("got innertHMLT=" + n.innerHTML); @@ -21825,15 +21839,18 @@ 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 ; - + var margin = style['margin-left']; + if (typeof(margin_to_depth[margin]) == 'undefined') { + max_margins++; + margin_to_depth[margin] = max_margins; + } + nlvl = margin_to_depth[margin] ; if (nlvl > lvl) { //new indent diff --git a/roojs-ui.js b/roojs-ui.js index 1cd385810c..6880d15005 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -985,12 +985,13 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac }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].trim()]=kv[1];});return C;},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');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);}}); +}var C=A.getElementsByTagName('h2');for(var i=0;iF){var N=B.createElement('ul'); +if(!H){H=B.createElement('li');G[F].appendChild(H);}H.appendChild(N);G[nlvl]=N;}F=nlvl;var O=G[nlvl].appendChild(B.createElement('li'));H=O;O.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