Skip to content
This repository was archived by the owner on Feb 6, 2020. It is now read-only.

Commit df06206

Browse files
committed
fix the img tag
1 parent 2b4fd9d commit df06206

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

autoload/server/static/scripts/index.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
html = document.querySelector('html');
88
mkdContainer = document.getElementById('js-markdown');
99

10+
function fixAllImg(text) {
11+
var match, reg = /<img[^>]+?(src=("|')([^\2]+?)\2)[^>]+?>/g;
12+
while((match = reg.exec(text)) !== null) {
13+
if(match && match.length === 4) {
14+
text = text.replace(match[3], getAbsPath(location.search, match[3]));
15+
}
16+
}
17+
return text;
18+
}
19+
1020
function getAbsPath(base, path) {
1121
var bases = Base64.decode(base.slice(1)).split('/')
1222
var paths = path.split('/');
@@ -63,6 +73,7 @@
6373
if(line.indexOf(flagSign) !== -1) {
6474
html[i] = line.replace(flagSign, '') + aPoint;
6575
}
76+
html[i] = fixAllImg(html[i]);
6677
}
6778
return html.join('\n');
6879
};
@@ -90,7 +101,7 @@
90101
};
91102

92103
renderer.paragraph = function(text) {
93-
text = text.replace(flagSign, aPoint);
104+
text = fixAllImg(text.replace(flagSign, aPoint));
94105
return '<p>' + text + '</p>\n';
95106
};
96107

@@ -118,7 +129,6 @@
118129
text = text.replace(flagSign, '');
119130
result = aPoint;
120131
}
121-
href = getAbsPath(location.search, href);
122132
return result + rImage.call(renderer, href, title, text);
123133
};
124134

0 commit comments

Comments
 (0)