Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check both front and back for metadata to avoid generating new CardIDs #129

Merged
merged 1 commit into from
Jun 9, 2024
Merged
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
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
Loading