Skip to content

Commit fcee5b6

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 dc31b4c commit fcee5b6

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

docs/step.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@
230230
if (!response.ok) throw new Error(`HTTP ${response.status}`);
231231
let md = await response.text();
232232
md = processMarkdown(md);
233+
// Fix relative image paths to resolve against the markdown file's directory
234+
const stepDir = step.file.substring(0, step.file.lastIndexOf('/') + 1);
235+
md = md.replace(/!\[([^\]]*)\]\((?!https?:\/\/|\/\/)([^)]+)\)/g, (match, alt, path) => {
236+
const cleanPath = path.replace(/^\.\//, '');
237+
return `![${alt}](${GITHUB_RAW_BASE}${stepDir}${cleanPath})`;
238+
});
233239
content.innerHTML = marked.parse(md);
234240
content.style.display = 'block';
235241

0 commit comments

Comments
 (0)