Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修改让没有host的img链接能添加host #71

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wxParse/html2json.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/

var __placeImgeUrlHttps = "https";
var __host ="http://127.0.0.1";
var __emojisReg = '';
var __emojisBaseSrc = '';
var __emojis = {};
Expand Down Expand Up @@ -128,6 +129,7 @@ function html2json(html, bindName) {
node.imgIndex = results.images.length;
var imgUrl = node.attr.src;
imgUrl = wxDiscode.urlToHttpUrl(imgUrl, __placeImgeUrlHttps);
imgUrl = wxDiscode.urlAddHost(imgUrl, __host);
node.attr.src = imgUrl;
node.from = bindName;
results.images.push(node);
Expand Down
21 changes: 19 additions & 2 deletions wxParse/wxDiscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,25 @@ function urlToHttpUrl(url,rep){
}
return url;
}
function urlAddHost(url,host){
let pat1=new RegExp("^http");
let result= pat1.test(url);
if(!result){
let pat2 = new RegExp("^/");
let result2 = pat2.test(url);
if(result2){
url = host+url;

}else{
url =host+"/"+url;
}

}
return url;
}

module.exports = {
strDiscode:strDiscode,
urlToHttpUrl:urlToHttpUrl
}
urlToHttpUrl:urlToHttpUrl,
urlAddHost:urlAddHost
}