Skip to content

Commit c294133

Browse files
brunoborgesCopilot
andcommitted
fix: resolve relative image paths in step.html viewer
Images referenced from markdown files with relative paths (e.g., ./images/foo.png) were broken when rendered through step.html on GitHub Pages. Added path rewriting in loadStep() to resolve image URLs against the markdown file's directory. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5438679 commit c294133

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

docs/step.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,13 @@
375375
let md = await response.text();
376376
md = processMarkdown(md);
377377

378+
// Fix relative image paths to resolve against the markdown file's directory
379+
const stepDir = step.file.substring(0, step.file.lastIndexOf('/') + 1);
380+
md = md.replace(/!\[([^\]]*)\]\((?!https?:\/\/|\/\/)([^)]+)\)/g, (match, alt, path) => {
381+
const cleanPath = path.replace(/^\.\//, '');
382+
return `![${alt}](${GITHUB_RAW_BASE}${stepDir}${cleanPath})`;
383+
});
384+
378385
marked.setOptions({ breaks: true, gfm: true });
379386
document.getElementById('markdown-content').innerHTML = marked.parse(md);
380387

0 commit comments

Comments
 (0)