93 lines
4.7 KiB
JavaScript
93 lines
4.7 KiB
JavaScript
function e(e) {
|
|
for (var t = {}, r = e.split(","), s = 0; s < r.length; s++) t[r[s]] = !0;
|
|
return t;
|
|
}
|
|
|
|
function t(e) {
|
|
var t = [];
|
|
if (0 == r.length || !a) return (d = {}).node = "text", d.text = e, [ d ];
|
|
e = e.replace(/\[([^\[\]]+)\]/g, ":$1:");
|
|
for (var o = new RegExp("[:]"), n = e.split(o), i = 0; i < n.length; i++) {
|
|
var l = n[i], d = {};
|
|
a[l] ? (d.node = "element", d.tag = "emoji", d.text = a[l], d.baseSrc = s) : (d.node = "text",
|
|
d.text = l), t.push(d);
|
|
}
|
|
return t;
|
|
}
|
|
|
|
var r = "", s = "", a = {}, o = require("./wxDiscode.js"), n = require("./htmlparser.js"), i = (e("area,base,basefont,br,col,frame,hr,img,input,link,meta,param,embed,command,keygen,source,track,wbr"),
|
|
e("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")), l = e("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"), d = e("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");
|
|
|
|
e("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected"),
|
|
e("wxxxcode-style,script,style,view,scroll-view,block"), module.exports = {
|
|
html2json: function(e, r) {
|
|
e = function(e) {
|
|
return e.replace(/<\?xml.*\?>\n/, "").replace(/<.*!doctype.*\>\n/, "").replace(/<.*!DOCTYPE.*\>\n/, "");
|
|
}(e), e = o.strDiscode(e);
|
|
var s = [], a = {
|
|
node: r,
|
|
nodes: [],
|
|
images: [],
|
|
imageUrls: []
|
|
};
|
|
return n(e, {
|
|
start: function(e, t, n) {
|
|
var c = {
|
|
node: "element",
|
|
tag: e
|
|
};
|
|
if (i[e] ? c.tagType = "block" : l[e] ? c.tagType = "inline" : d[e] && (c.tagType = "closeSelf"),
|
|
0 !== t.length && (c.attr = t.reduce(function(e, t) {
|
|
var r = t.name, s = t.value;
|
|
return "class" == r && (console.log(s), c.classStr = s), "style" == r && (console.log(s),
|
|
c.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" === c.tag) {
|
|
c.imgIndex = a.images.length;
|
|
var u = c.attr.src;
|
|
u = o.urlToHttpUrl(u, "https"), c.attr.src = u, c.from = r, a.images.push(c), a.imageUrls.push(u);
|
|
}
|
|
if ("font" === c.tag) {
|
|
var p = [ "x-small", "small", "medium", "large", "x-large", "xx-large", "-webkit-xxx-large" ], m = {
|
|
color: "color",
|
|
face: "font-family",
|
|
size: "font-size"
|
|
};
|
|
for (var f in c.attr.style || (c.attr.style = []), c.styleStr || (c.styleStr = ""),
|
|
m) if (c.attr[f]) {
|
|
var h = "size" === f ? p[c.attr[f] - 1] : c.attr[f];
|
|
c.attr.style.push(m[f]), c.attr.style.push(h), c.styleStr += m[f] + ": " + h + ";";
|
|
}
|
|
}
|
|
if ("source" === c.tag && (a.source = c.attr.src), n) {
|
|
var g = s[0] || a;
|
|
void 0 === g.nodes && (g.nodes = []), g.nodes.push(c);
|
|
} else s.unshift(c);
|
|
},
|
|
end: function(e) {
|
|
var t = s.shift();
|
|
if (t.tag !== e && console.error("invalid state: mismatch end tag"), "video" === t.tag && a.source && (t.attr.src = a.source,
|
|
delete result.source), 0 === s.length) a.nodes.push(t); else {
|
|
var r = s[0];
|
|
void 0 === r.nodes && (r.nodes = []), r.nodes.push(t);
|
|
}
|
|
},
|
|
chars: function(e) {
|
|
var r = {
|
|
node: "text",
|
|
text: e,
|
|
textArray: t(e)
|
|
};
|
|
if (0 === s.length) a.nodes.push(r); else {
|
|
var o = s[0];
|
|
void 0 === o.nodes && (o.nodes = []), o.nodes.push(r);
|
|
}
|
|
},
|
|
comment: function(e) {}
|
|
}), a;
|
|
},
|
|
emojisInit: function() {
|
|
var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "", t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "/wxParse/emojis/", o = arguments[2];
|
|
r = e, s = t, a = o;
|
|
}
|
|
}; |