var __placeImgeUrlHttps="https",__emojisReg="",__emojisBaseSrc="",__emojis={},wxDiscode=require("./wxDiscode.js"),HTMLParser=require("./htmlparser.js"),empty=makeMap("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr"),block=makeMap("br,a,code,address,article,applet,aside,audio,blockquote,button,canvas,center,dd,del,dir,div,dl,dt,fieldset,figcaption,figure,footer,form,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,output,p,pre,section,script,table,tbody,td,tfoot,th,thead,tr,ul,video"),inline=makeMap("abbr,acronym,applet,b,basefont,bdo,big,button,cite,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,strong,sub,sup,textarea,tt,u,var"),closeSelf=makeMap("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr"),fillAttrs=makeMap("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),special=makeMap("wxxxcode-style,script,style,view,scroll-view,block");function makeMap(e){for(var t={},r=e.split(","),s=0;s<r.length;s++)t[r[s]]=!0;return t}function q(e){return'"'+e+'"'}function removeDOCTYPE(e){return e.replace(/<\?xml.*\?>\n/,"").replace(/<.*!doctype.*\>\n/,"").replace(/<.*!DOCTYPE.*\>\n/,"")}function trimHtml(e){return e.replace(/\r?\n+/g,"").replace(/<!--.*?-->/gi,"").replace(/\/\*.*?\*\//gi,"").replace(/[ ]+</gi,"<")}function html2json(e,t){e=trimHtml(e=removeDOCTYPE(e)),e=wxDiscode.strDiscode(e);var r=[],s={node:t,nodes:[],images:[],imageUrls:[]},a=0;return HTMLParser(e,{start:function(e,o,i){var n,l={node:"element",tag:e};0===r.length?(l.index=a.toString(),a+=1):(void 0===(n=r[0]).nodes&&(n.nodes=[]),l.index=n.index+"."+n.nodes.length);if(block[e]?l.tagType="block":inline[e]?l.tagType="inline":closeSelf[e]&&(l.tagType="closeSelf"),0!==o.length&&(l.attr=o.reduce((function(e,t){var r=t.name,s=t.value;return"class"==r&&(l.classStr=s),"style"==r&&(l.styleStr=s),s.match(/ /)&&(s=s.split(" ")),e[r]?Array.isArray(e[r])?e[r].push(s):e[r]=[e[r],s]:e[r]=s,e}),{})),"img"===l.tag){l.imgIndex=s.images.length;var c=l.attr.src;""==c[0]&&c.splice(0,1),c=wxDiscode.urlToHttpUrl(c,__placeImgeUrlHttps),l.attr.src=c,l.from=t,s.images.push(l),s.imageUrls.push(c)}if("font"===l.tag){var d=["x-small","small","medium","large","x-large","xx-large","-webkit-xxx-large"],m={color:"color",face:"font-family",size:"font-size"};for(var p in l.attr.style||(l.attr.style=[]),l.styleStr||(l.styleStr=""),m)if(l.attr[p]){var u="size"===p?d[l.attr[p]-1]:l.attr[p];l.attr.style.push(m[p]),l.attr.style.push(u),l.styleStr+=m[p]+": "+u+";"}}("source"===l.tag&&(s.source=l.attr.src),i)?(void 0===(n=r[0]||s).nodes&&(n.nodes=[]),n.nodes.push(l)):r.unshift(l)},end:function(e){var t=r.shift();if(t.tag!==e&&console.error("invalid state: mismatch end tag"),"video"===t.tag&&s.source&&(t.attr.src=s.source,delete s.source),0===r.length)s.nodes.push(t);else{var a=r[0];void 0===a.nodes&&(a.nodes=[]),a.nodes.push(t)}},chars:function(e){var t={node:"text",text:e,textArray:transEmojiStr(e)};if(0===r.length)t.index=a.toString(),a+=1,s.nodes.push(t);else{var o=r[0];void 0===o.nodes&&(o.nodes=[]),t.index=o.index+"."+o.nodes.length,o.nodes.push(t)}},comment:function(e){}}),s}function transEmojiStr(e){var t=[];if(0==__emojisReg.length||!__emojis)return(i={node:"text"}).text=e,s=[i];e=e.replace(/\[([^\[\]]+)\]/g,":$1:");for(var r=new RegExp("[:]"),s=e.split(r),a=0;a<s.length;a++){var o=s[a],i={};__emojis[o]?(i.node="element",i.tag="emoji",i.text=__emojis[o],i.baseSrc=__emojisBaseSrc):(i.node="text",i.text=o),t.push(i)}return t}function emojisInit(e="",t="/wxParse/emojis/",r){__emojisReg=e,__emojisBaseSrc=t,__emojis=r}module.exports={html2json:html2json,emojisInit:emojisInit};