From 2cfdb79fff3002c90caf628027bc9b39c4e0d216 Mon Sep 17 00:00:00 2001 From: "alexcolucci@protonmail.com" Date: Fri, 4 Feb 2022 23:24:58 +0100 Subject: [PATCH] Add support for Cloze #9 --- README.md | 2 + manifest.json | 2 +- src/entities/clozecard.ts | 4 +- src/regex.ts | 10 ++--- src/services/anki.ts | 30 +++++++++++-- src/services/parser.ts | 92 ++++++++++++++++++++++++++++++++++++--- 6 files changed, 121 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 685f1cc..d48250b 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,10 @@ Anki integration for [Obsidian](https://obsidian.md/). 📅 Spaced-only cards with **#card-spaced** or **#card/spaced** ✍️ Inline style with **Question::Answer** ✍️ Inline style reversed with **Question:::Answer** +📃 Cloze with **==Highlight==** or **{Curly brackets}** or **{2:Cloze}** 🧠 **Context-aware** mode 🏷️ Global and local **tags** + 🔢 Support for **LaTeX** 🖼️ Support for **images** 🎤 Support for **audios** diff --git a/manifest.json b/manifest.json index 3458100..4e3a83b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "flashcards-obsidian", "name": "Flashcards", - "version": "1.5.6", + "version": "1.6.0", "minAppVersion": "0.9.17", "description": "Anki integration", "author": "Alex Colucci", diff --git a/src/entities/clozecard.ts b/src/entities/clozecard.ts index f564f0e..6864785 100644 --- a/src/entities/clozecard.ts +++ b/src/entities/clozecard.ts @@ -28,7 +28,7 @@ export class Clozecard extends Card { mediaNames, containsCode ); - this.modelName = `Obsidian-clozed`; + this.modelName = `Obsidian-cloze`; if (fields["Source"]) { this.modelName += sourceDeckExtension; } @@ -69,6 +69,6 @@ export class Clozecard extends Card { }; public getIdFormat(): string { - return "^" + this.id.toString() + "\n"; + return "\n^" + this.id.toString(); } } diff --git a/src/regex.ts b/src/regex.ts index d1ad679..ca217e1 100644 --- a/src/regex.ts +++ b/src/regex.ts @@ -80,13 +80,11 @@ export class Regex { 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); + 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; + this.singleClozeCurly = /((?:{)(?:(\d):?)?(.+?)(?:}))/g; + this.singleClozeHighlight = /((?:==)(.+?)(?:==))/g; } } \ No newline at end of file diff --git a/src/services/anki.ts b/src/services/anki.ts index 3ff991f..174bec4 100644 --- a/src/services/anki.ts +++ b/src/services/anki.ts @@ -233,19 +233,23 @@ export class Anki { } const css = - '.card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: "#";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n'; + '.card {\r\n font-family: arial;\r\n font-size: 20px;\r\n text-align: center;\r\n color: black;\r\n background-color: white;\r\n}\r\n\r\n.tag::before {\r\n\tcontent: "#";\r\n}\r\n\r\n.tag {\r\n color: white;\r\n background-color: #9F2BFF;\r\n border: none;\r\n font-size: 11px;\r\n font-weight: bold;\r\n padding: 1px 8px;\r\n margin: 0px 3px;\r\n text-align: center;\r\n text-decoration: none;\r\n cursor: pointer;\r\n border-radius: 14px;\r\n display: inline;\r\n vertical-align: middle;\r\n}\r\n .cloze { font-weight: bold; color: blue;}.nightMode .cloze { color: lightblue;}'; const front = `{{Front}}\r\n

{{Tags}}<\/p>\r\n\r\n