diff --git a/front-end/index.html b/front-end/index.html
index 44da6dc9..8251e610 100644
--- a/front-end/index.html
+++ b/front-end/index.html
@@ -975,21 +975,38 @@
window.fileCache.set(path, text);
}
- // SCF_GATEWAY must contains protocol and resources can't be in encrypted path
- const renderer = new marked.Renderer();
- renderer.image = (href, title, text) => {
- if (href.startsWith('./') || href.startsWith('../')) {
- href = new URL(href, window.GLOBAL_CONFIG.SCF_GATEWAY + path).href;
- }
- return ``;
- };
- renderer.link = (href, title, text) => {
- if (href.startsWith('./') || href.startsWith('../')) {
- href = new URL(href, window.GLOBAL_CONFIG.SCF_GATEWAY + path).href;
+ // It is not possible to load resources that are not cached and in an encrypted path.
+ const transformHref = (href) => {
+ if (href.startsWith('http') || href.startsWith('//')) {
+ return href;
}
- return `${text}`;
+
+ const dummyBase = new URL(
+ window.backFordwardCache.current + '/',
+ location
+ );
+ const absPath = new URL(href, dummyBase).href.slice(
+ location.origin.length
+ );
+
+ const containingPath = (path) =>
+ path.slice(0, path.lastIndexOf('/')) || '/';
+
+ return (
+ window.fileCache
+ .get(containingPath(absPath))
+ ?.files.find(({ name }) => name === absPath.split('/').pop())
+ ?.url ||
+ window.GLOBAL_CONFIG.SCF_GATEWAY.replace(/\/$/, '') + absPath
+ );
};
+ const renderer = new marked.Renderer();
+ renderer.image = (href, title, text) =>
+ ``;
+ renderer.link = (href, title, text) =>
+ `${text}`;
+
text = marked.parse(text, {
gfm: true,
renderer: renderer,