Skip to content

Commit 80aa4fa

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 9667ad0 commit 80aa4fa

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

docs/step.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,14 @@
419419
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
420420
let md = await resp.text();
421421
md = processMarkdown(md);
422+
423+
// Fix relative image paths to resolve against the markdown file's directory
424+
const stepDir = step.file.substring(0, step.file.lastIndexOf('/') + 1);
425+
md = md.replace(/!\[([^\]]*)\]\((?!https?:\/\/|\/\/)([^)]+)\)/g, (match, alt, path) => {
426+
const cleanPath = path.replace(/^\.\//, '');
427+
return `![${alt}](${GITHUB_RAW_BASE}${stepDir}${cleanPath})`;
428+
});
429+
422430
content.innerHTML = marked.parse(md);
423431
content.style.display = 'block';
424432
} catch (err) {

0 commit comments

Comments
 (0)