Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []
Expand Down