2 * @class Roo.htmleditor.FilterWord
3 * try and clean up all the mess that Word generates.
5 * This is the 'nice version' - see 'Heavy' that white lists a very short list of elements, and multi-filters
8 * Run a new Span Filter
9 * @param {Object} config Configuration options
12 Roo.htmleditor.FilterWord = function(cfg)
14 // no need to apply config.
18 Roo.extend(Roo.htmleditor.FilterWord, Roo.htmleditor.Filter,
24 * Clean up MS wordisms...
26 replaceTag : function(node)
29 // no idea what this does - span with text, replaceds with just text.
31 node.nodeName == 'SPAN' &&
32 !node.hasAttributes() &&
33 node.childNodes.length == 1 &&
34 node.firstChild.nodeName == "#text"
36 var textNode = node.firstChild;
37 node.removeChild(textNode);
38 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
39 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" "), node);
41 node.parentNode.insertBefore(textNode, node);
42 if (node.getAttribute('lang') != 'zh-CN') { // do not space pad on chinese characters..
43 node.parentNode.insertBefore(node.ownerDocument.createTextNode(" ") , node);
46 node.parentNode.removeChild(node);
47 return false; // dont do chidren - we have remove our node - so no need to do chdhilren?
52 if (node.tagName.toLowerCase().match(/^(style|script|applet|embed|noframes|noscript)$/)) {
53 node.parentNode.removeChild(node);
54 return false; // dont do chidlren
56 //Roo.log(node.tagName);
57 // remove - but keep children..
58 if (node.tagName.toLowerCase().match(/^(meta|link|\\?xml:|st1:|o:|v:|font)/)) {
59 //Roo.log('-- removed');
60 while (node.childNodes.length) {
61 var cn = node.childNodes[0];
63 node.parentNode.insertBefore(cn, node);
64 // move node to parent - and clean it..
67 node.parentNode.removeChild(node);
68 /// no need to iterate chidlren = it's got none..
69 //this.iterateChildren(node, this.cleanWord);
70 return false; // no need to iterate children.
73 if (node.className.length) {
75 var cn = node.className.split(/\W+/);
77 Roo.each(cn, function(cls) {
78 if (cls.match(/Mso[a-zA-Z]+/)) {
83 node.className = cna.length ? cna.join(' ') : '';
85 node.removeAttribute("class");
89 if (node.hasAttribute("lang")) {
90 node.removeAttribute("lang");
93 if (node.hasAttribute("style")) {
95 var styles = node.getAttribute("style").split(";");
97 Roo.each(styles, function(s) {
101 var kv = s.split(":");
102 if (kv[0].match(/^(mso-|line|font|background|margin|padding|color)/)) {
105 // what ever is left... we allow.
108 node.setAttribute("style", nstyle.length ? nstyle.join(';') : '');
109 if (!nstyle.length) {
110 node.removeAttribute('style');
113 return true; // do children