fix word filter on html editor
authorAlan <alan@roojs.com>
Wed, 20 Apr 2022 06:05:18 +0000 (14:05 +0800)
committerAlan <alan@roojs.com>
Wed, 20 Apr 2022 06:05:18 +0000 (14:05 +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 3cb8df6..d267920 100644 (file)
@@ -179,6 +179,8 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
         var lvl = 0;
         var stack = [ ul ];
         var last_li = false;
+        var base_lvl = 0;
+        
         items.forEach(function(n) {
             //Roo.log("got innertHMLT=" + n.innerHTML);
             
@@ -212,11 +214,20 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             }
             
             var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1;
-            if (nlvl > lvl && last_li) {
+            
+            
+            
+            if (nlvl > lvl) {
                 //new indent
-                var nul = doc.createElement('ul'); // what about number lists...
-                last_li.appendChild(nul);
-                stack[nlvl] = nul;
+                if (last_li) {
+                    var nul = doc.createElement('ul'); // what about number lists...
+                    last_li.appendChild(nul);
+                    stack[nlvl] = nul;
+                } else {
+                    // occurs when we get a level (1) but no parent - just put all the children on the top most..
+                    stack[nlvl] = stack[stack.length-1]; 
+                }
+                
             }
             lvl = nlvl;
             
index 307a86a..725e532 100644 (file)
@@ -1932,9 +1932,9 @@ 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]]=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;i<G.length;i++){H=this.styleToObject(G[i]);
-if(typeof(H['mso-list'])=='undefined'){continue;}G[i].parentNode.removeChild(G[i]);break;}H=this.styleToObject(n);if(typeof(H['mso-list'])=='undefined'){A.removeChild(n);return;}var I=(H['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(I>D&&F){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);}});
+ns=ns.nextSibling;}var ul=A.ownerDocument.createElement('ul');A.insertBefore(ul,p);var D=0;var E=[ul];var F=false;var G=0;C.forEach(function(n){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){if(F){var K=B.createElement('ul');
+F.appendChild(K);E[J]=K;}else{E[J]=E[E.length-1];}}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 c5e35d3..58357f4 100644 (file)
@@ -26663,7 +26663,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             }
             
             var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1;
-            if (nlvl > lvl) {
+            if (nlvl > lvl && last_li) {
                 //new indent
                 var nul = doc.createElement('ul'); // what about number lists...
                 last_li.appendChild(nul);
index 0dae4c7..74bf8c3 100644 (file)
@@ -1152,7 +1152,7 @@ A.removeChild(cn);A.parentNode.insertBefore(cn,A);if(cn.nodeType==1){this.replac
 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;i<G.length;i++){H=this.styleToObject(G[i]);
-if(typeof(H['mso-list'])=='undefined'){continue;}G[i].parentNode.removeChild(G[i]);break;}H=this.styleToObject(n);if(typeof(H['mso-list'])=='undefined'){A.removeChild(n);return;}var I=(H['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(I>D){var J=B.createElement('ul');
+if(typeof(H['mso-list'])=='undefined'){continue;}G[i].parentNode.removeChild(G[i]);break;}H=this.styleToObject(n);if(typeof(H['mso-list'])=='undefined'){A.removeChild(n);return;}var I=(H['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(I>D&&F){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;
index b72198f..c8a7c4e 100644 (file)
@@ -46244,6 +46244,8 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
         var lvl = 0;
         var stack = [ ul ];
         var last_li = false;
+        var base_lvl = 0;
+        
         items.forEach(function(n) {
             //Roo.log("got innertHMLT=" + n.innerHTML);
             
@@ -46277,11 +46279,20 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             }
             
             var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1;
-            if (nlvl > lvl && last_li) {
+            
+            
+            
+            if (nlvl > lvl) {
                 //new indent
-                var nul = doc.createElement('ul'); // what about number lists...
-                last_li.appendChild(nul);
-                stack[nlvl] = nul;
+                if (last_li) {
+                    var nul = doc.createElement('ul'); // what about number lists...
+                    last_li.appendChild(nul);
+                    stack[nlvl] = nul;
+                } else {
+                    // occurs when we get a level (1) but no parent - just put all the children on the top most..
+                    stack[nlvl] = stack[stack.length-1]; 
+                }
+                
             }
             lvl = nlvl;
             
index cb4aab9..4f5f9ac 100644 (file)
@@ -21752,6 +21752,8 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
         var lvl = 0;
         var stack = [ ul ];
         var last_li = false;
+        var base_lvl = 0;
+        
         items.forEach(function(n) {
             //Roo.log("got innertHMLT=" + n.innerHTML);
             
@@ -21785,11 +21787,20 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
             }
             
             var nlvl = (style['mso-list'].split(' ')[1].replace(/level/,'') *1) - 1;
-            if (nlvl > lvl && last_li) {
+            
+            
+            
+            if (nlvl > lvl) {
                 //new indent
-                var nul = doc.createElement('ul'); // what about number lists...
-                last_li.appendChild(nul);
-                stack[nlvl] = nul;
+                if (last_li) {
+                    var nul = doc.createElement('ul'); // what about number lists...
+                    last_li.appendChild(nul);
+                    stack[nlvl] = nul;
+                } else {
+                    // occurs when we get a level (1) but no parent - just put all the children on the top most..
+                    stack[nlvl] = stack[stack.length-1]; 
+                }
+                
             }
             lvl = nlvl;
             
index d319e31..e898310 100644 (file)
@@ -986,9 +986,9 @@ 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]]=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;i<G.length;i++){H=this.styleToObject(G[i]);
-if(typeof(H['mso-list'])=='undefined'){continue;}G[i].parentNode.removeChild(G[i]);break;}H=this.styleToObject(n);if(typeof(H['mso-list'])=='undefined'){A.removeChild(n);return;}var I=(H['mso-list'].split(' ')[1].replace(/level/,'')*1)-1;if(I>D&&F){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);}});
+ns=ns.nextSibling;}var ul=A.ownerDocument.createElement('ul');A.insertBefore(ul,p);var D=0;var E=[ul];var F=false;var G=0;C.forEach(function(n){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){if(F){var K=B.createElement('ul');
+F.appendChild(K);E[J]=K;}else{E[J]=E[E.length-1];}}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);