From 85f45fe849dce5caf0e207d20645f979efe07f6b Mon Sep 17 00:00:00 2001 From: Javon Hickmon Date: Thu, 19 Mar 2026 16:53:14 -0700 Subject: [PATCH] Added support for relative file pathing --- main.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/main.ts b/main.ts index edddc70..e4b7728 100644 --- a/main.ts +++ b/main.ts @@ -70,9 +70,19 @@ export default class EmbedCodeFile extends Plugin { return } } else { - const errMsg = "`ERROR: invalid source path, use 'vault://...' or 'http[s]://...'`" - await MarkdownRenderer.renderMarkdown(errMsg, el, '', this) - return + // Relative path: resolve against the current note's folder + const noteFolder = ctx.sourcePath.includes("/") + ? ctx.sourcePath.substring(0, ctx.sourcePath.lastIndexOf("/")) + : ""; + const resolvedPath = noteFolder ? `${noteFolder}/${srcPath}` : srcPath; + const tFile = app.vault.getAbstractFileByPath(resolvedPath); + if (tFile instanceof TFile) { + fullSrc = await app.vault.read(tFile); + } else { + const errMsg = `\`ERROR: couldn't read file '${resolvedPath}' (resolved from relative path '${srcPath}')\``; + await MarkdownRenderer.renderMarkdown(errMsg, el, "", this); + return; + } } let srcLinesNum: number[] = []