Skip to content

Commit 6ed1f27

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 0f5d450 commit 6ed1f27

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
@@ -773,6 +773,13 @@
773773

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

777784
// Configure marked
778785
marked.setOptions({

0 commit comments

Comments
 (0)