Skip to content

Commit 5314d25

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 4884a1c commit 5314d25

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
@@ -770,6 +770,13 @@
770770

771771
let md = await response.text();
772772
md = processMarkdown(md);
773+
774+
// Fix relative image paths to resolve against the markdown file's directory
775+
const stepDir = step.file.substring(0, step.file.lastIndexOf('/') + 1);
776+
md = md.replace(/!\[([^\]]*)\]\((?!https?:\/\/|\/\/)([^)]+)\)/g, (match, alt, path) => {
777+
const cleanPath = path.replace(/^\.\//, '');
778+
return `![${alt}](${GITHUB_RAW_BASE}${stepDir}${cleanPath})`;
779+
});
773780

774781
// Configure marked
775782
marked.setOptions({

0 commit comments

Comments
 (0)