Skip to content

Commit

Permalink
Check both front and back for metadata to avoid generating new CardID…
Browse files Browse the repository at this point in the history
…s on each call to Anki:SendToOwnDeck (#129)

Co-authored-by: ccammack <clc1024@hotmail.com>
  • Loading branch information
ccammack and ccammack committed Jun 9, 2024
1 parent 3f8a90e commit cc6303d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/markdown/parsers/cardParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class CardParser extends BaseParser {
let noteId = 0;
let isCloze = false;

const fillBackAndTags = (line: string) => {
const appendLine = (line: string, dest: string[]) => {
// set tags
if (this.tagRe.test(line)) {
tags.push(...this.parseTags(line));
Expand All @@ -85,13 +85,13 @@ export class CardParser extends BaseParser {
}
}

// set back
// set dest
// skip first blank lines
if (back.length === 0 && !line) {
if (dest.length === 0 && !line) {
return;
}

back.push(line);
dest.push(line);
};

if (cardLines.length === 1) {
Expand All @@ -106,13 +106,12 @@ export class CardParser extends BaseParser {
return;
}

fillBackAndTags(line);
appendLine(line, back);
});
} else {
// front card has multiple lines
front.push(...cardLines[0]);

trimArray(cardLines[1]).forEach((line: string) => fillBackAndTags(line));
trimArray(cardLines[0]).forEach((line: string) => appendLine(line, front));
trimArray(cardLines[1]).forEach((line: string) => appendLine(line, back));
}

return {
Expand Down

0 comments on commit cc6303d

Please sign in to comment.