Skip to content

Commit 8176774

Browse files
committed
Fix markdown rendering of image links and non-md links within the site
1 parent f7b6ab3 commit 8176774

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

markdown/index.html

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,18 @@ <h2>Table of Contents</h2>
160160
return hash.toLowerCase();
161161
}
162162

163+
function toSiteURL(url) {
164+
if (url.hostname == 'api.github.com' && url.pathname.startsWith('/repos/eclipse-platform/www.eclipse.org-eclipse/contents')) {
165+
const result = new URL(window.location);
166+
result.pathname = url.pathname.replace(/\/repos\/eclipse-platform\/www.eclipse.org-eclipse\/contents/, '/eclipse')
167+
result.hash = url.hash;
168+
result.search = url.search;
169+
return result;
170+
} else {
171+
return null;
172+
}
173+
}
174+
163175
function generateFileList(files) {
164176
const fileElements = files.map(file => {
165177
const fileURL = new URL(file.url);
@@ -212,8 +224,18 @@ <h2>Table of Contents</h2>
212224
const imgs = targetElement.querySelectorAll("img[src]");
213225
for (const img of imgs) {
214226
const src = img.getAttribute('src');
227+
if (src == null) {
228+
continue;
229+
}
230+
215231
if (!src.startsWith('http')) {
216-
img.src = `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${src}`;
232+
const logicalSrc = new URL(src, logicalBaseURL);
233+
const siteURL = toSiteURL(logicalSrc);
234+
if (siteURL != null) {
235+
img.src = siteURL;
236+
} else {
237+
img.src = `https://raw.githubusercontent.com/${org}/${repo}/${branch}/${src}`;
238+
}
217239
}
218240
}
219241

@@ -230,6 +252,14 @@ <h2>Table of Contents</h2>
230252
}
231253

232254
const logicalHref = new URL(href, logicalBaseURL);
255+
if (!logicalHref.pathname.endsWith('.md')) {
256+
const siteURL = toSiteURL(logicalHref);
257+
if (siteURL != null) {
258+
a.href = siteURL;
259+
}
260+
continue;
261+
}
262+
233263
const url = new URL(window.location);
234264
url.hash = fixHash(logicalHref.hash);
235265
if (logicalHref.hostname == 'api.github.com') {

0 commit comments

Comments
 (0)