mirror of
https://github.com/gosticks/flashcards-obsidian.git
synced 2025-10-16 12:05:33 +00:00
Fix broken update #76
This commit is contained in:
parent
907b844f44
commit
0c2d5f61c4
@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "flashcards-obsidian",
|
||||
"name": "Flashcards",
|
||||
"version": "1.5.5",
|
||||
"version": "1.5.6",
|
||||
"minAppVersion": "0.9.17",
|
||||
"description": "Anki integration",
|
||||
"author": "Alex Colucci",
|
||||
|
||||
72
src/entities/clozecard.ts
Normal file
72
src/entities/clozecard.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import { codeDeckExtension, sourceDeckExtension } from "src/constants";
|
||||
import { Card } from "src/entities/card";
|
||||
|
||||
export class Clozecard extends Card {
|
||||
constructor(
|
||||
id = -1,
|
||||
deckName: string,
|
||||
initialContent: string,
|
||||
fields: Record<string, string>,
|
||||
reversed: boolean,
|
||||
endOffset: number,
|
||||
tags: string[] = [],
|
||||
inserted = false,
|
||||
mediaNames: string[],
|
||||
containsCode: boolean
|
||||
) {
|
||||
super(
|
||||
id,
|
||||
deckName,
|
||||
initialContent,
|
||||
fields,
|
||||
reversed,
|
||||
endOffset,
|
||||
tags,
|
||||
inserted,
|
||||
mediaNames,
|
||||
containsCode
|
||||
);
|
||||
this.modelName = `Obsidian-clozed`;
|
||||
if (fields["Source"]) {
|
||||
this.modelName += sourceDeckExtension;
|
||||
}
|
||||
if (containsCode) {
|
||||
this.modelName += codeDeckExtension;
|
||||
}
|
||||
}
|
||||
|
||||
public getCard(update = false): object {
|
||||
const card: any = {
|
||||
deckName: this.deckName,
|
||||
modelName: this.modelName,
|
||||
fields: this.fields,
|
||||
tags: this.tags,
|
||||
};
|
||||
|
||||
if (update) {
|
||||
card["id"] = this.id;
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
public getMedias(): object[] {
|
||||
const medias: object[] = [];
|
||||
this.mediaBase64Encoded.forEach((data, index) => {
|
||||
medias.push({
|
||||
filename: this.mediaNames[index],
|
||||
data: data,
|
||||
});
|
||||
});
|
||||
|
||||
return medias;
|
||||
}
|
||||
|
||||
public toString = (): string => {
|
||||
return `Cloze: ${this.fields[0]}`;
|
||||
};
|
||||
|
||||
public getIdFormat(): string {
|
||||
return "^" + this.id.toString() + "\n";
|
||||
}
|
||||
}
|
||||
20
src/regex.ts
20
src/regex.ts
@ -5,6 +5,7 @@ export class Regex {
|
||||
wikiImageLinks: RegExp;
|
||||
markdownImageLinks: RegExp;
|
||||
wikiAudioLinks: RegExp;
|
||||
obsidianCodeBlock: RegExp;
|
||||
codeBlock: RegExp;
|
||||
cardsDeckLine: RegExp;
|
||||
cardsToDelete: RegExp;
|
||||
@ -13,6 +14,10 @@ export class Regex {
|
||||
flashscardsWithTag: RegExp;
|
||||
cardsInlineStyle: RegExp;
|
||||
cardsSpacedStyle: RegExp;
|
||||
cardsClozeWholeLine: RegExp;
|
||||
singleClozeCurly: RegExp;
|
||||
singleClozeHighlight: RegExp;
|
||||
clozeHighlight: RegExp;
|
||||
|
||||
constructor(settings: ISettings) {
|
||||
this.update(settings);
|
||||
@ -31,6 +36,9 @@ export class Regex {
|
||||
this.wikiAudioLinks =
|
||||
/!\[\[(.*\.(?:mp3|webm|wav|m4a|ogg|3gp|flac)).*?\]\]/gim;
|
||||
|
||||
// https://regex101.com/r/eqnJeW/1
|
||||
this.obsidianCodeBlock = /(?:```(?:.*?\n?)+?```)(?:\n|$)/gim;
|
||||
|
||||
this.codeBlock = /<code\b[^>]*>(.*?)<\/code>/gims;
|
||||
|
||||
this.cardsDeckLine = /cards-deck: [\p{L}]+/giu;
|
||||
@ -70,5 +78,15 @@ export class Regex {
|
||||
settings.flashcardsTag +
|
||||
"[/-]spaced)((?: *#[\\p{Letter}-]+)*) *\\n?(?:\\^(\\d{13}))?";
|
||||
this.cardsSpacedStyle = new RegExp(str, flags);
|
||||
|
||||
// https://regex101.com/r/cgtnLf/1
|
||||
// str = "(?:.*?(==(.*?)==).*)(?:\n?^(d{13}))?";
|
||||
// this.clozeHighlight = /((==)(.*?)(==))/gm;
|
||||
|
||||
// str = "( {0,3}[#]{0,6})?(?:(?:[\t ]*)(?:\\d.|[-+*]|#{1,6}))?(.*?(==.+?==|{.+?}).*?)((?: *#[\\w-]+)+|$)(?:\n\\^(?:\\d{13}))?"
|
||||
// this.cardsClozeWholeLine = new RegExp(str, flags);
|
||||
|
||||
// this.singleClozeCurly = /((?:{)(?:(\d):?)?(.+?)(?:}))/g;
|
||||
// this.singleClozeHighlight = /((?:==)(.+?)(?:==))/g;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,9 @@ import { Regex } from "src/regex";
|
||||
import { Flashcard } from "../entities/flashcard";
|
||||
import { Inlinecard } from "src/entities/inlinecard";
|
||||
import { Spacedcard } from "src/entities/spacedcard";
|
||||
import { Clozecard } from "src/entities/clozecard";
|
||||
import { escapeMarkdown } from "src/utils";
|
||||
import { Card } from "src/entities/card";
|
||||
|
||||
export class Parser {
|
||||
private regex: Regex;
|
||||
@ -40,6 +42,11 @@ export class Parser {
|
||||
headings = [...file.matchAll(this.regex.headingsRegex)];
|
||||
}
|
||||
|
||||
// filter in cacheCodeSections only the objects with type "code"
|
||||
// the line is 0-indexed
|
||||
// const codeSections = this.app.metadataCache.getFileCache(this.app.workspace.getActiveFile()).sections.filter(section => section.type === "code")
|
||||
|
||||
|
||||
note = this.substituteObsidianLinks(`[[${note}]]`, vault);
|
||||
cards = cards.concat(
|
||||
this.generateCardsWithTag(file, headings, deck, vault, note, globalTags)
|
||||
@ -50,6 +57,9 @@ export class Parser {
|
||||
cards = cards.concat(
|
||||
this.generateSpacedCards(file, headings, deck, vault, note, globalTags)
|
||||
);
|
||||
// cards = cards.concat(
|
||||
// this.generateClozeCards(file, headings, deck, vault, note, globalTags)
|
||||
// );
|
||||
cards.sort((a, b) => a.endOffset - b.endOffset);
|
||||
|
||||
const defaultAnkiTag = this.settings.defaultAnkiTag;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user