工具类 util.img
/**
* @description transform emotion image url between code
* @author x.radish
* @param {String} html the html contents
* @return {String}
*/
transformImg:function (html) {
var imgReg = /<img\s+data-type=['|"]emotion['|"]\s+src\s*=\s*['|"]([^\s'"]+).*?\/?>/g;
var codeReg = /\[:(\d{1,3}):\]/g;
if (imgReg.test(html)) {
html = html.replace(imgReg, function (match, capture) {
var temp = capture.split("/");
return "[:" + temp[temp.length - 1].split(".")[0] + ":]";
});
} else {
html = html.replace(codeReg, function (match, capture) {
return "<img data-type='emotion' src='emotion/" + capture + ".gif' />";
});
}
return html;
}