From 89b03a0009ad29be68bd417551948042c2b146b3 Mon Sep 17 00:00:00 2001 From: Alan Date: Thu, 21 Jul 2022 17:34:00 +0800 Subject: [PATCH] remove debug code from word filter --- Roo/HtmlEditorCore.js | 2 +- Roo/htmleditor/FilterWord.js | 50 +++++++++++++++++++++++++++------- roojs-all.js | 21 ++++++++------- roojs-bootstrap-debug.js | 52 ++++++++++++++++++++++++++++-------- roojs-bootstrap.js | 21 ++++++++------- roojs-debug.js | 52 ++++++++++++++++++++++++++++-------- roojs-ui-debug.js | 52 ++++++++++++++++++++++++++++-------- roojs-ui.js | 21 ++++++++------- 8 files changed, 200 insertions(+), 71 deletions(-) diff --git a/Roo/HtmlEditorCore.js b/Roo/HtmlEditorCore.js index db6b8eced2..a1c38cd9e5 100644 --- a/Roo/HtmlEditorCore.js +++ b/Roo/HtmlEditorCore.js @@ -634,7 +634,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterStyleToTag({ node : d }); new Roo.htmleditor.FilterAttributes({ node : d, - attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width'], + attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'], attrib_clean : ['href', 'src' ] }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); diff --git a/Roo/htmleditor/FilterWord.js b/Roo/htmleditor/FilterWord.js index 6fefb3e23c..a2eeebd43a 100644 --- a/Roo/htmleditor/FilterWord.js +++ b/Roo/htmleditor/FilterWord.js @@ -168,12 +168,26 @@ 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 ++) { listpara.item(i).className = "MsoListParagraph"; } + + listpara = doc.getElementsByClassName('MsoListParagraphCxSpMiddle'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('MsoListParagraphCxSpLast'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('ql-indent-1'); + 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 ++) { @@ -189,11 +203,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, listpara.item(0).className = "MsoNormalx"; } } - listpara = doc.getElementsByClassName('ql-indent-1'); - while(listpara.length) { - this.replaceDocBullet(listpara.item(0)); - } + listpara = doc.getElementsByClassName('MsoListParagraph'); + + + //Roo.log(doc.innerHTML); + while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -211,7 +226,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, doc = parent.ownerDocument, items = []; - + var listtype = 'ul'; while (ns) { if (ns.nodeType != 1) { ns = ns.nextSibling; @@ -220,10 +235,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) { items.push(ns); ns = ns.nextSibling; has_list = true; + if (spans.length && spans[0].hasAttribute('style')) { + var style = this.styleToObject(spans[0]); + if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) { + listtype = 'ol'; + } + } + continue; } var spans = ns.getElementsByTagName('span'); @@ -250,7 +273,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, return; } - var ul = parent.ownerDocument.createElement('ul'); // what about number lists... + var ul = parent.ownerDocument.createElement(listtype); // what about number lists... parent.insertBefore(ul, p); var lvl = 0; var stack = [ ul ]; @@ -273,7 +296,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } - + var num = 1; var style = {}; for(var i = 0; i < spans.length; i++) { @@ -281,7 +304,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (typeof(style['mso-list']) == 'undefined') { continue; } - + if (listtype == 'ol') { + num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1; + } spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. break; } @@ -304,7 +329,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (nlvl > lvl) { //new indent - var nul = doc.createElement('ul'); // what about number lists... + var nul = doc.createElement(listtype); // what about number lists... if (!last_li) { last_li = doc.createElement('li'); stack[lvl].appendChild(last_li); @@ -315,6 +340,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } lvl = nlvl; + // not starting at 1.. + if (!stack[nlvl].hasAttribute("start") && num > 1) { + stack[nlvl].setAttribute("start", num); + } + var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; nli.innerHTML = n.innerHTML; diff --git a/roojs-all.js b/roojs-all.js index c62db20f99..03d41d86a9 100644 --- a/roojs-all.js +++ b/roojs-all.js @@ -1932,14 +1932,17 @@ 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;},replaceAname:function(A){var aa=Array.from(A.getElementsByTagName('a'));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);}}); +}if(a.hasAttribute("href")){continue;}this.removeNodeKeepChildren(a);}},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');for(var i=0;iH){var Q=B.createElement(D);if(!J){J=B.createElement('li');I[H].appendChild(J);}J.appendChild(Q);I[nlvl]=Q;}H=nlvl;if(!I[nlvl].hasAttribute("start")&&N>1){I[nlvl].setAttribute("start",N);}var R=I[nlvl].appendChild(B.createElement('li')); +J=R;R.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); @@ -2089,7 +2092,7 @@ this.pushValue();},onPasteEvent:function(e,v){var cd=(e.browserEvent.clipboardDa this.insertAtCursor('');return false;}if(cd.types.indexOf('text/html')<0){return false;}var C=[];var D=cd.getData('text/html');if(cd.types.indexOf('text/rtf')>-1){var E=new Roo.rtf.Parser(cd.getData('text/rtf'));C=E.doc?E.doc.getElementsByType('pict'):[]; }C=C.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable|footerf)/);}).map(function(g){return g.toDataURL();}).filter(function(g){return g!='about:blank';});D=this.cleanWordChars(D);var d=(new DOMParser().parseFromString(D,'text/html')).body; var sn=this.getParentElement();if(d.getElementsByTagName('table').length&&sn&&sn.closest('table')){e.preventDefault();this.insertAtCursor("You can not nest tables");return false;}if(C.length>0){var ar=Array.from(d.getElementsByTagName('v:imagedata'));Roo.each(ar,function(F){F.parentNode.insertBefore(d.ownerDocument.createElement('img'),F); -F.parentNode.removeChild(F);});Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',C[i]);});}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-width'],attrib_clean:['href','src']} +F.parentNode.removeChild(F);});Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',C[i]);});}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-width','start'],attrib_clean:['href','src']} );new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT',':']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});new Roo.htmleditor.FilterComment({node:d} );}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return;}var G=new Roo.htmleditor.BlockFigure({image_src:F.src});G.updateElement(F);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); }e.preventDefault();return false;},onDestroy:function(){if(this.rendered){}},onFirstFocus:function(){this.assignDocWin();this.undoManager=new Roo.lib.UndoManager(100,(this.doc.body||this.doc.documentElement));this.activated=true;if(Roo.isGecko){this.win.focus(); diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index 5d2c70fb30..4c3502b749 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -26648,12 +26648,26 @@ 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 ++) { listpara.item(i).className = "MsoListParagraph"; } + + listpara = doc.getElementsByClassName('MsoListParagraphCxSpMiddle'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('MsoListParagraphCxSpLast'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('ql-indent-1'); + 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 ++) { @@ -26669,11 +26683,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, listpara.item(0).className = "MsoNormalx"; } } - listpara = doc.getElementsByClassName('ql-indent-1'); - while(listpara.length) { - this.replaceDocBullet(listpara.item(0)); - } + listpara = doc.getElementsByClassName('MsoListParagraph'); + Roo.log(doc.innerHTML); + + + while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -26691,7 +26706,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, doc = parent.ownerDocument, items = []; - + var listtype = 'ul'; while (ns) { if (ns.nodeType != 1) { ns = ns.nextSibling; @@ -26700,10 +26715,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) { items.push(ns); ns = ns.nextSibling; has_list = true; + if (spans.length && spans[0].hasAttribute('style')) { + var style = this.styleToObject(spans[0]); + if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) { + listtype = 'ol'; + } + } + continue; } var spans = ns.getElementsByTagName('span'); @@ -26730,7 +26753,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, return; } - var ul = parent.ownerDocument.createElement('ul'); // what about number lists... + var ul = parent.ownerDocument.createElement(listtype); // what about number lists... parent.insertBefore(ul, p); var lvl = 0; var stack = [ ul ]; @@ -26753,7 +26776,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } - + var num = 1; var style = {}; for(var i = 0; i < spans.length; i++) { @@ -26761,7 +26784,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (typeof(style['mso-list']) == 'undefined') { continue; } - + if (listtype == 'ol') { + num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1; + } spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. break; } @@ -26784,7 +26809,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (nlvl > lvl) { //new indent - var nul = doc.createElement('ul'); // what about number lists... + var nul = doc.createElement(listtype); // what about number lists... if (!last_li) { last_li = doc.createElement('li'); stack[lvl].appendChild(last_li); @@ -26795,6 +26820,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } lvl = nlvl; + // not starting at 1.. + if (!stack[nlvl].hasAttribute("start") && num > 1) { + stack[nlvl].setAttribute("start", num); + } + var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; nli.innerHTML = n.innerHTML; @@ -29539,7 +29569,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterStyleToTag({ node : d }); new Roo.htmleditor.FilterAttributes({ node : d, - attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width'], + attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'], attrib_clean : ['href', 'src' ] }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index dd79e07980..eeb5e4dc04 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1151,14 +1151,17 @@ 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;},replaceAname:function(A){var aa=Array.from(A.getElementsByTagName('a'));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);}}); +}if(a.hasAttribute("href")){continue;}this.removeNodeKeepChildren(a);}},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');for(var i=0;iH){var Q=B.createElement(D);if(!J){J=B.createElement('li');I[H].appendChild(J);}J.appendChild(Q);I[nlvl]=Q;}H=nlvl;if(!I[nlvl].hasAttribute("start")&&N>1){I[nlvl].setAttribute("start",N);}var R=I[nlvl].appendChild(B.createElement('li')); +J=R;R.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); @@ -1277,7 +1280,7 @@ this.pushValue();},onPasteEvent:function(e,v){var cd=(e.browserEvent.clipboardDa this.insertAtCursor('');return false;}if(cd.types.indexOf('text/html')<0){return false;}var C=[];var D=cd.getData('text/html');if(cd.types.indexOf('text/rtf')>-1){var E=new Roo.rtf.Parser(cd.getData('text/rtf'));C=E.doc?E.doc.getElementsByType('pict'):[]; }C=C.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable|footerf)/);}).map(function(g){return g.toDataURL();}).filter(function(g){return g!='about:blank';});D=this.cleanWordChars(D);var d=(new DOMParser().parseFromString(D,'text/html')).body; var sn=this.getParentElement();if(d.getElementsByTagName('table').length&&sn&&sn.closest('table')){e.preventDefault();this.insertAtCursor("You can not nest tables");return false;}if(C.length>0){var ar=Array.from(d.getElementsByTagName('v:imagedata'));Roo.each(ar,function(F){F.parentNode.insertBefore(d.ownerDocument.createElement('img'),F); -F.parentNode.removeChild(F);});Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',C[i]);});}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-width'],attrib_clean:['href','src']} +F.parentNode.removeChild(F);});Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',C[i]);});}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-width','start'],attrib_clean:['href','src']} );new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT',':']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});new Roo.htmleditor.FilterComment({node:d} );}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return;}var G=new Roo.htmleditor.BlockFigure({image_src:F.src});G.updateElement(F);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); }e.preventDefault();return false;},onDestroy:function(){if(this.rendered){}},onFirstFocus:function(){this.assignDocWin();this.undoManager=new Roo.lib.UndoManager(100,(this.doc.body||this.doc.documentElement));this.activated=true;if(Roo.isGecko){this.win.focus(); diff --git a/roojs-debug.js b/roojs-debug.js index b3be73aa08..db783cf0d6 100644 --- a/roojs-debug.js +++ b/roojs-debug.js @@ -46262,12 +46262,26 @@ 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 ++) { listpara.item(i).className = "MsoListParagraph"; } + + listpara = doc.getElementsByClassName('MsoListParagraphCxSpMiddle'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('MsoListParagraphCxSpLast'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('ql-indent-1'); + 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 ++) { @@ -46283,11 +46297,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, listpara.item(0).className = "MsoNormalx"; } } - listpara = doc.getElementsByClassName('ql-indent-1'); - while(listpara.length) { - this.replaceDocBullet(listpara.item(0)); - } + listpara = doc.getElementsByClassName('MsoListParagraph'); + + + //Roo.log(doc.innerHTML); + while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -46305,7 +46320,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, doc = parent.ownerDocument, items = []; - + var listtype = 'ul'; while (ns) { if (ns.nodeType != 1) { ns = ns.nextSibling; @@ -46314,10 +46329,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) { items.push(ns); ns = ns.nextSibling; has_list = true; + if (spans.length && spans[0].hasAttribute('style')) { + var style = this.styleToObject(spans[0]); + if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) { + listtype = 'ol'; + } + } + continue; } var spans = ns.getElementsByTagName('span'); @@ -46344,7 +46367,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, return; } - var ul = parent.ownerDocument.createElement('ul'); // what about number lists... + var ul = parent.ownerDocument.createElement(listtype); // what about number lists... parent.insertBefore(ul, p); var lvl = 0; var stack = [ ul ]; @@ -46367,7 +46390,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } - + var num = 1; var style = {}; for(var i = 0; i < spans.length; i++) { @@ -46375,7 +46398,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (typeof(style['mso-list']) == 'undefined') { continue; } - + if (listtype == 'ol') { + num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1; + } spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. break; } @@ -46398,7 +46423,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (nlvl > lvl) { //new indent - var nul = doc.createElement('ul'); // what about number lists... + var nul = doc.createElement(listtype); // what about number lists... if (!last_li) { last_li = doc.createElement('li'); stack[lvl].appendChild(last_li); @@ -46409,6 +46434,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } lvl = nlvl; + // not starting at 1.. + if (!stack[nlvl].hasAttribute("start") && num > 1) { + stack[nlvl].setAttribute("start", num); + } + var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; nli.innerHTML = n.innerHTML; @@ -50420,7 +50450,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterStyleToTag({ node : d }); new Roo.htmleditor.FilterAttributes({ node : d, - attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width'], + attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'], attrib_clean : ['href', 'src' ] }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); diff --git a/roojs-ui-debug.js b/roojs-ui-debug.js index c9b83ff0a1..e76a862c52 100644 --- a/roojs-ui-debug.js +++ b/roojs-ui-debug.js @@ -21770,12 +21770,26 @@ 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 ++) { listpara.item(i).className = "MsoListParagraph"; } + + listpara = doc.getElementsByClassName('MsoListParagraphCxSpMiddle'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('MsoListParagraphCxSpLast'); + for( var i = 0; i < listpara.length; i ++) { + listpara.item(i).className = "MsoListParagraph"; + } + listpara = doc.getElementsByClassName('ql-indent-1'); + 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 ++) { @@ -21791,11 +21805,12 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, listpara.item(0).className = "MsoNormalx"; } } - listpara = doc.getElementsByClassName('ql-indent-1'); - while(listpara.length) { - this.replaceDocBullet(listpara.item(0)); - } + listpara = doc.getElementsByClassName('MsoListParagraph'); + + + //Roo.log(doc.innerHTML); + while(listpara.length) { this.replaceDocBullet(listpara.item(0)); @@ -21813,7 +21828,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, doc = parent.ownerDocument, items = []; - + var listtype = 'ul'; while (ns) { if (ns.nodeType != 1) { ns = ns.nextSibling; @@ -21822,10 +21837,18 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (!ns.className.match(/(MsoListParagraph|ql-indent-1)/i)) { break; } + var spans = ns.getElementsByTagName('span'); if (ns.hasAttribute('style') && ns.getAttribute('style').match(/mso-list/)) { items.push(ns); ns = ns.nextSibling; has_list = true; + if (spans.length && spans[0].hasAttribute('style')) { + var style = this.styleToObject(spans[0]); + if (typeof(style['font-family']) != 'undefined' && !style['font-family'].match(/Symbol/)) { + listtype = 'ol'; + } + } + continue; } var spans = ns.getElementsByTagName('span'); @@ -21852,7 +21875,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, return; } - var ul = parent.ownerDocument.createElement('ul'); // what about number lists... + var ul = parent.ownerDocument.createElement(listtype); // what about number lists... parent.insertBefore(ul, p); var lvl = 0; var stack = [ ul ]; @@ -21875,7 +21898,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } - + var num = 1; var style = {}; for(var i = 0; i < spans.length; i++) { @@ -21883,7 +21906,9 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (typeof(style['mso-list']) == 'undefined') { continue; } - + if (listtype == 'ol') { + num = spans[i].innerText.replace(/[^0-9]+]/g,'') * 1; + } spans[i].parentNode.removeChild(spans[i]); // remove the fake bullet. break; } @@ -21906,7 +21931,7 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, if (nlvl > lvl) { //new indent - var nul = doc.createElement('ul'); // what about number lists... + var nul = doc.createElement(listtype); // what about number lists... if (!last_li) { last_li = doc.createElement('li'); stack[lvl].appendChild(last_li); @@ -21917,6 +21942,11 @@ Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter, } lvl = nlvl; + // not starting at 1.. + if (!stack[nlvl].hasAttribute("start") && num > 1) { + stack[nlvl].setAttribute("start", num); + } + var nli = stack[nlvl].appendChild(doc.createElement('li')); last_li = nli; nli.innerHTML = n.innerHTML; @@ -25928,7 +25958,7 @@ Roo.extend(Roo.HtmlEditorCore, Roo.Component, { new Roo.htmleditor.FilterStyleToTag({ node : d }); new Roo.htmleditor.FilterAttributes({ node : d, - attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width'], + attrib_white : ['href', 'src', 'name', 'align', 'colspan', 'rowspan', 'data-display', 'data-width', 'start'], attrib_clean : ['href', 'src' ] }); new Roo.htmleditor.FilterBlack({ node : d, tag : this.black}); diff --git a/roojs-ui.js b/roojs-ui.js index 363994f089..aaadc8656c 100644 --- a/roojs-ui.js +++ b/roojs-ui.js @@ -986,14 +986,17 @@ 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;},replaceAname:function(A){var aa=Array.from(A.getElementsByTagName('a'));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);}}); +}if(a.hasAttribute("href")){continue;}this.removeNodeKeepChildren(a);}},replaceDocBullets:function(A){var B=A.getElementsByClassName('MsoListParagraphCxSpFirst');for(var i=0;iH){var Q=B.createElement(D);if(!J){J=B.createElement('li');I[H].appendChild(J);}J.appendChild(Q);I[nlvl]=Q;}H=nlvl;if(!I[nlvl].hasAttribute("start")&&N>1){I[nlvl].setAttribute("start",N);}var R=I[nlvl].appendChild(B.createElement('li')); +J=R;R.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); @@ -1143,7 +1146,7 @@ this.pushValue();},onPasteEvent:function(e,v){var cd=(e.browserEvent.clipboardDa this.insertAtCursor('');return false;}if(cd.types.indexOf('text/html')<0){return false;}var C=[];var D=cd.getData('text/html');if(cd.types.indexOf('text/rtf')>-1){var E=new Roo.rtf.Parser(cd.getData('text/rtf'));C=E.doc?E.doc.getElementsByType('pict'):[]; }C=C.filter(function(g){return !g.path.match(/^rtf\/(head|pgdsctbl|listtable|footerf)/);}).map(function(g){return g.toDataURL();}).filter(function(g){return g!='about:blank';});D=this.cleanWordChars(D);var d=(new DOMParser().parseFromString(D,'text/html')).body; var sn=this.getParentElement();if(d.getElementsByTagName('table').length&&sn&&sn.closest('table')){e.preventDefault();this.insertAtCursor("You can not nest tables");return false;}if(C.length>0){var ar=Array.from(d.getElementsByTagName('v:imagedata'));Roo.each(ar,function(F){F.parentNode.insertBefore(d.ownerDocument.createElement('img'),F); -F.parentNode.removeChild(F);});Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',C[i]);});}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-width'],attrib_clean:['href','src']} +F.parentNode.removeChild(F);});Roo.each(d.getElementsByTagName('img'),function(F,i){F.setAttribute('src',C[i]);});}if(this.autoClean){new Roo.htmleditor.FilterWord({node:d});new Roo.htmleditor.FilterStyleToTag({node:d});new Roo.htmleditor.FilterAttributes({node:d,attrib_white:['href','src','name','align','colspan','rowspan','data-display','data-width','start'],attrib_clean:['href','src']} );new Roo.htmleditor.FilterBlack({node:d,tag:this.black});new Roo.htmleditor.FilterKeepChildren({node:d,tag:['FONT',':']});new Roo.htmleditor.FilterParagraph({node:d});new Roo.htmleditor.FilterSpan({node:d});new Roo.htmleditor.FilterLongBr({node:d});new Roo.htmleditor.FilterComment({node:d} );}if(this.enableBlocks){Array.from(d.getElementsByTagName('img')).forEach(function(F){if(F.closest('figure')){return;}var G=new Roo.htmleditor.BlockFigure({image_src:F.src});G.updateElement(F);});}this.insertAtCursor(d.innerHTML.replace(/ /g,' '));if(this.enableBlocks){Roo.htmleditor.Block.initAll(this.doc.body); }e.preventDefault();return false;},onDestroy:function(){if(this.rendered){}},onFirstFocus:function(){this.assignDocWin();this.undoManager=new Roo.lib.UndoManager(100,(this.doc.body||this.doc.documentElement));this.activated=true;if(Roo.isGecko){this.win.focus(); -- 2.39.2