Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/services/cards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ export class CardsService {
card.reversed ? (total += 2) : total++;
});

if(this.settings.sourceSupport){
this.parser.updateCardSource(cardsToCreate)
this.anki.updateCards(cardsToCreate)
}

this.updateFrontmatter(frontmatter, deckName);
this.writeAnkiBlocks(cardsToCreate);

Expand Down
11 changes: 9 additions & 2 deletions src/services/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,14 +493,21 @@ export class Parser {
return links;
}

public updateCardSource(cards: Card[]){
for(let card of cards){
if(card.id == null) continue
card.fields["Source"] = card.fields["Source"].replace("__BLOCK_ID__", String(card.id));
}
}

private substituteObsidianLinks(str: string, vaultName: string) {
const linkRegex = /\[\[(.+?)(?:\|(.+?))?\]\]/gim;
vaultName = encodeURIComponent(vaultName);

return str.replace(linkRegex, (match, filename, rename) => {
const href = `obsidian://open?vault=${vaultName}&file=${encodeURIComponent(
filename
)}.md`;
filename + "#^__BLOCK_ID__"
)}`;
const fileRename = rename ? rename : filename;
return `<a href="${href}">${fileRename}</a>`;
});
Expand Down