Skip to content

Commit

Permalink
Merge pull request #57 from alan16742/master
Browse files Browse the repository at this point in the history
feat: markdown relative path support
  • Loading branch information
vcheckzen authored Oct 8, 2024
2 parents 798a523 + b886545 commit 4c40e53
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,24 @@
window.fileCache.set(path, text);
}

// SCF_GATEWAY must contains protocol and resouces can't be in encrpted 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 `<img src="${href}" alt="${text}">`;
};
renderer.link = (href, title, text) => {
if (href.startsWith('./') || href.startsWith('../')) {
href = new URL(href, window.GLOBAL_CONFIG.SCF_GATEWAY + path).href;
}
return `<a href="${href}">${text}</a>`;
};

text = marked.parse(text, {
gfm: true,
renderer: renderer,
highlight: (code, language, callback) => {
try {
return hljs.highlight(code, {
Expand Down

0 comments on commit 4c40e53

Please sign in to comment.