Fix #7275 - handling odd word document
authorAlan <alan@roojs.com>
Tue, 21 Jun 2022 03:45:30 +0000 (11:45 +0800)
committerAlan <alan@roojs.com>
Tue, 21 Jun 2022 03:45:30 +0000 (11:45 +0800)
Roo/htmleditor/FilterWord.js
roojs-all.js
roojs-bootstrap-debug.js
roojs-bootstrap.js
roojs-debug.js
roojs-ui-debug.js
roojs-ui.js

index 351e170..27544a7 100644 (file)
@@ -144,16 +144,29 @@ 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);
         
-        var listpara = doc.getElementsByClassName('ql-indent-1');
+        var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst');
+        for( var i = 0; i < listpara.length; i ++) {
+            listpara.item(i).className = "MsoListParagraph";
+        }
+        // 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:/)) {
+                htwo.item(i).className = "MsoListParagraph";
+            }
+        }
+        
+        listpara = doc.getElementsByClassName('ql-indent-1');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
-        
-        var listpara = doc.getElementsByClassName('MsoListParagraph');
+        listpara = doc.getElementsByClassName('MsoListParagraph');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
+      
     },
     
     replaceDocBullet : function(p)
@@ -223,6 +236,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             if (nlvl > lvl) {
                 //new indent
                 var nul = doc.createElement('ul'); // what about number lists...
+                if (!last_li) {
+                    last_li = doc.createElement('li');
+                    stack[lvl].appendChild(last_li);
+                }
                 last_li.appendChild(nul);
                 stack[nlvl] = nul;
                 
index 4bcf870..39a3e49 100644 (file)
@@ -1930,11 +1930,12 @@ return false;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|nofr
 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].trim()]=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');
+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;i<B.length;i++){B.item(i).className="MsoListParagraph";
+}var C=A.getElementsByTagName('h2');for(var i=0;i<C.length;i++){if(C.item(i).getAttribute('style').match(/mso-list:/)){C.item(i).className="MsoListParagraph";}}B=A.getElementsByClassName('ql-indent-1');while(B.length){this.replaceDocBullet(B.item(0));}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,G){var H=n.getElementsByTagName('span');if(!H.length){A.removeChild(n);return;}var I={};for(var i=0;i<H.length;i++){I=this.styleToObject(H[i]);
 if(typeof(I['mso-list'])=='undefined'){continue;}H[i].parentNode.removeChild(H[i]);break;}I=this.styleToObject(n);if(typeof(I['mso-list'])=='undefined'){A.removeChild(n);return;}var J=(I['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(J>D){var K=B.createElement('ul');
-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);}});
+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);}});
 // 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);
index 50855fd..ea98f39 100644 (file)
@@ -26597,16 +26597,29 @@ 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);
         
-        var listpara = doc.getElementsByClassName('ql-indent-1');
+        var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst');
+        for( var i = 0; i < listpara.length; i ++) {
+            listpara.item(i).className = "MsoListParagraph";
+        }
+        // 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:/)) {
+                htwo.item(i).className = "MsoListParagraph";
+            }
+        }
+        
+        listpara = doc.getElementsByClassName('ql-indent-1');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
-        
-        var listpara = doc.getElementsByClassName('MsoListParagraph');
+        listpara = doc.getElementsByClassName('MsoListParagraph');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
+      
     },
     
     replaceDocBullet : function(p)
@@ -26676,6 +26689,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             if (nlvl > lvl) {
                 //new indent
                 var nul = doc.createElement('ul'); // what about number lists...
+                if (!last_li) {
+                    last_li = doc.createElement('li');
+                    stack[lvl].appendChild(last_li);
+                }
                 last_li.appendChild(nul);
                 stack[nlvl] = nul;
                 
index fd24130..6e4e3ee 100644 (file)
@@ -1149,11 +1149,12 @@ return false;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|nofr
 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].trim()]=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');
+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;i<B.length;i++){B.item(i).className="MsoListParagraph";
+}var C=A.getElementsByTagName('h2');for(var i=0;i<C.length;i++){if(C.item(i).getAttribute('style').match(/mso-list:/)){C.item(i).className="MsoListParagraph";}}B=A.getElementsByClassName('ql-indent-1');while(B.length){this.replaceDocBullet(B.item(0));}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,G){var H=n.getElementsByTagName('span');if(!H.length){A.removeChild(n);return;}var I={};for(var i=0;i<H.length;i++){I=this.styleToObject(H[i]);
 if(typeof(I['mso-list'])=='undefined'){continue;}H[i].parentNode.removeChild(H[i]);break;}I=this.styleToObject(n);if(typeof(I['mso-list'])=='undefined'){A.removeChild(n);return;}var J=(I['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(J>D){var K=B.createElement('ul');
-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);}});
+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);}});
 // 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);
index 52f214f..779fa01 100644 (file)
@@ -46211,16 +46211,29 @@ 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);
         
-        var listpara = doc.getElementsByClassName('ql-indent-1');
+        var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst');
+        for( var i = 0; i < listpara.length; i ++) {
+            listpara.item(i).className = "MsoListParagraph";
+        }
+        // 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:/)) {
+                htwo.item(i).className = "MsoListParagraph";
+            }
+        }
+        
+        listpara = doc.getElementsByClassName('ql-indent-1');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
-        
-        var listpara = doc.getElementsByClassName('MsoListParagraph');
+        listpara = doc.getElementsByClassName('MsoListParagraph');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
+      
     },
     
     replaceDocBullet : function(p)
@@ -46290,6 +46303,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             if (nlvl > lvl) {
                 //new indent
                 var nul = doc.createElement('ul'); // what about number lists...
+                if (!last_li) {
+                    last_li = doc.createElement('li');
+                    stack[lvl].appendChild(last_li);
+                }
                 last_li.appendChild(nul);
                 stack[nlvl] = nul;
                 
index 04f9443..6623fbf 100644 (file)
@@ -21719,16 +21719,29 @@ 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);
         
-        var listpara = doc.getElementsByClassName('ql-indent-1');
+        var listpara = doc.getElementsByClassName('MsoListParagraphCxSpFirst');
+        for( var i = 0; i < listpara.length; i ++) {
+            listpara.item(i).className = "MsoListParagraph";
+        }
+        // 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:/)) {
+                htwo.item(i).className = "MsoListParagraph";
+            }
+        }
+        
+        listpara = doc.getElementsByClassName('ql-indent-1');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
-        
-        var listpara = doc.getElementsByClassName('MsoListParagraph');
+        listpara = doc.getElementsByClassName('MsoListParagraph');
         while(listpara.length) {
             this.replaceDocBullet(listpara.item(0));
         }
+      
     },
     
     replaceDocBullet : function(p)
@@ -21798,6 +21811,10 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             if (nlvl > lvl) {
                 //new indent
                 var nul = doc.createElement('ul'); // what about number lists...
+                if (!last_li) {
+                    last_li = doc.createElement('li');
+                    stack[lvl].appendChild(last_li);
+                }
                 last_li.appendChild(nul);
                 stack[nlvl] = nul;
                 
index 985e256..40ce72d 100644 (file)
@@ -984,11 +984,12 @@ return false;}if(A.tagName.toLowerCase().match(/^(style|script|applet|embed|nofr
 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].trim()]=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');
+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;i<B.length;i++){B.item(i).className="MsoListParagraph";
+}var C=A.getElementsByTagName('h2');for(var i=0;i<C.length;i++){if(C.item(i).getAttribute('style').match(/mso-list:/)){C.item(i).className="MsoListParagraph";}}B=A.getElementsByClassName('ql-indent-1');while(B.length){this.replaceDocBullet(B.item(0));}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,G){var H=n.getElementsByTagName('span');if(!H.length){A.removeChild(n);return;}var I={};for(var i=0;i<H.length;i++){I=this.styleToObject(H[i]);
 if(typeof(I['mso-list'])=='undefined'){continue;}H[i].parentNode.removeChild(H[i]);break;}I=this.styleToObject(n);if(typeof(I['mso-list'])=='undefined'){A.removeChild(n);return;}var J=(I['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(J>D){var K=B.createElement('ul');
-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);}});
+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);}});
 // 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);