/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:28
*/
KISSY.add("editor/core/htmlDataProcessor",function(g,q){return{init:function(m){function k(a){if((a.getAttribute("class")+"").match(/Apple-\w+-span/)||!a.attributes.length)a.setTagName(null);else if(!a.childNodes.length&&!a.attributes.length)return!1}function r(a){return a.replace(s,function(a,b,o){return"<"+b+o.replace(t,function(a,c){return-1==o.indexOf("_ke_saved_"+c)?" _ke_saved_"+a+" "+a:a})+">"})}function u(a){return a.replace(v,function(a){return"<ke:encoded>"+encodeURIComponent(a)+"</ke:encoded>"})}
function w(a){return a.replace(x,function(a,b){return decodeURIComponent(b)})}var y=g.Node,n=g.UA,b=g.require("htmlparser"),i=new b.Filter,l=new b.Filter;(function(){function a(a){a=b.serialize(a);return new b.Comment(j+encodeURIComponent(a).replace(/--/g,"%2D%2D"))}var c={tagNames:[[/^\?xml.*$/i,""],[/^.*namespace.*$/i,""]],attributeNames:[[/^on/,"ke_on"],[/^lang$/,""]],tags:{script:a,noscript:a,span:k}},e={tagNames:[[/^ke:/,""],[/^\?xml:namespace$/,""]],tags:{$:function(a){if(a.attributes.length)for(var b=
["name","href","src"],c,d=0;d<b.length;d++)c="_ke_saved_"+b[d],a.getAttribute(c)&&a.removeAttribute(b[d]);return a},embed:function(a){var b=a.parentNode;if(b&&"object"==b.nodeName){var c=b.getAttribute("width"),b=b.getAttribute("height");c&&a.setAttribute("width",c);b&&a.setAttribute("width",b)}},a:function(a){if(!a.childNodes.length&&!a.attributes.length)return!1},span:k},attributes:{style:function(a){if(!g.trim(a))return!1}},attributeNames:[[/^_ke_saved_/,""],[/^ke_on/,"on"],[/^_ke.*/,""],[/^ke:.*$/,
""],[/^_ks.*/,""]],comment:function(a){if(a.substr(0,j.length)==j)return a=g.trim(decodeURIComponent(a.substr(j.length))),b.parse(a).childNodes[0]}};n.ie&&(e.attributes.style=function(a){return a.replace(/(^|;)([^:]+)/g,function(a){return a.toLowerCase()})});i.addRules(e);l.addRules(c)})();(function(){function a(a){for(var a=a.childNodes,b=a.length,c=a[b-1];c&&3==c.nodeType&&!g.trim(c.nodeValue);)c=a[--b];return c}function c(b,c){var d=a(b);d&&((c||!n.ie)&&1==d.nodeType&&"br"==d.nodeName?b.removeChild(d):
3==d.nodeType&&m.test(d.nodeValue)&&b.removeChild(d))}function e(b){var c=a(b);return!c||1==c.nodeType&&"br"==c.nodeName||"form"==b.nodeName&&"input"==c.nodeName}function j(a){c(a,!0);e(a)&&(n.ie?a.appendChild(new b.Text(" ")):(a.appendChild(new b.Text("&nbsp;")),a.appendChild(new b.Tag("br"))))}function k(a){c(a,!1);e(a)&&a.appendChild(new b.Text(" "))}var m=/^[\t\r\n ]*(?:&nbsp;|\xa0)$/,d=q.XHTML_DTD,h=g.merge(d.$block,d.$listItem,d.$tableContent),f;for(f in h)h.hasOwnProperty(f)&&("br"in d[f]||
delete h[f]);delete h.td;delete h.pre;var d={tags:{}},p={tags:{}};for(f in h)h.hasOwnProperty(f)&&(d.tags[f]=j,p.tags[f]=k);l.addRules(d);i.addRules(p)})();i.addRules({text:function(a){return a.replace(/\xa0/g,"&nbsp;")}});var s=/<(a|area|img|input)\b([^>]*)>/gi,t=/\b(href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi,j="{ke_protected}",v=/(?:<style[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,x=/<ke:encoded>([^<]*)<\/ke:encoded>/gi,z=/(<\/?)((?:object|embed|param|html|body|head|title|script|noscript)[^>]*>)/gi,
A=/(<\/?)ke:((?:object|embed|param|html|body|head|title|script|noscript)[^>]*>)/gi,B=/<ke:(param|embed)([^>]*?)\/?>(?!\s*<\/ke:\1)/gi;m.htmlDataProcessor={dataFilter:l,htmlFilter:i,toHtml:function(a){var c=new b.BeautifyWriter;(new b.Parser(a)).parse().writeHtml(c,i);return a=c.getHtml()},toDataFormat:function(a,c){var c=c||l,a=r(a),a=u(a),a=a.replace(z,"$1ke:$2"),a=a.replace(B,"<ke:$1$2></ke:$1>"),e=new y("<div>");e.html("a"+a);a=e.html().substr(1);a=a.replace(A,"$1$2");a=w(a);e=new b.BasicWriter;
(new b.Parser(a)).parse().writeHtml(e,c);return a=e.getHtml()},toServer:function(a){var c=new b.MinifyWriter;(new b.Parser(a)).parse().writeHtml(c,i);return c.getHtml()}}}}},{requires:["./base"]});
