Skip to content

Commit

Permalink
fix: fixes #10 by treating resources similar to obsidian by using thi…
Browse files Browse the repository at this point in the history
…s.metadataCache.getFirstLinkpathDest method
  • Loading branch information
debanjandhar12 committed Nov 23, 2021
1 parent 3093597 commit 2f943bf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/clozeblock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ export class ClozeBlock extends Block {
const originalImageRender = md.renderer.rules.image;
md.renderer.rules.image = (...a) => {
if((encodeURI(a[0][a[1]].src).match(isImage) && !encodeURI(a[0][a[1]].src).match(isWebURL))) { // Image is relative to vault
// @ts-expect-error
let imgPath = path.join(this.vault.adapter.basePath,a[0][a[1]].src);
AnkiConnect.storeMediaFileByPath(encodeURIComponent(a[0][a[1]].src), imgPath); // Flatten and save
try {
// @ts-expect-error
let imgPath = path.join(this.vault.adapter.basePath,this.metadataCache.getFirstLinkpathDest(a[0][a[1]].src, this.file.path).path);
AnkiConnect.storeMediaFileByPath(encodeURIComponent(a[0][a[1]].src), imgPath); // Flatten and save
}
catch {}
a[0][a[1]].src = encodeURIComponent(a[0][a[1]].src); // Flatten image and convert to markdown.
}
return originalImageRender(...a);
Expand Down

0 comments on commit 2f943bf

Please sign in to comment.