From fc8f33ea8839f8e220c6d4520a3b253412ddb1a6 Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Sun, 14 Apr 2024 20:20:01 +0800 Subject: [PATCH 01/21] complete add path but not work well --- data.json | 218 +++++++++++++++++++++++++++ main.ts | 1 + manifest.json | 8 +- obsidian_to_anki.py | 2 +- package-lock.json | 4 +- package.json | 6 +- src/file.ts | 17 ++- src/files-manager.ts | 5 +- src/interfaces/settings-interface.ts | 5 +- src/note.ts | 1 + src/setting-to-data.ts | 1 + src/settings.ts | 6 +- 12 files changed, 257 insertions(+), 17 deletions(-) create mode 100644 data.json diff --git a/data.json b/data.json new file mode 100644 index 00000000..12cd1c62 --- /dev/null +++ b/data.json @@ -0,0 +1,218 @@ +{ + "settings": { + "CUSTOM_REGEXPS": { + "Basic": "", + "Basic+": "", + "Basic++": "", + "Basic+++": "", + "Basic-73fde": "", + "Cloze ALL": "", + "Pot Card 2": "", + "Python - Basic": "", + "Python - Basic (and reversed card)": "", + "Python - Cloze": "", + "UVBasic-English": "", + "单词": "", + "图片遮盖": "", + "填空题": "", + "红宝书": "", + "问答题": "", + "问答题(同时生成翻转的卡片<可选>)": "", + "问答题(同时生成翻转的卡片)": "", + "问答题(输入答案)": "" + }, + "FILE_LINK_FIELDS": { + "Basic": "Front", + "Basic+": "Front", + "Basic++": "Front", + "Basic+++": "Front", + "Basic-73fde": "Front", + "Cloze ALL": "文字", + "Pot Card 2": "Front", + "Python - Basic": "Front", + "Python - Basic (and reversed card)": "Front", + "Python - Cloze": "Text", + "UVBasic-English": "英语单词", + "单词": "单词", + "图片遮盖": "遮盖", + "填空题": "文字", + "红宝书": "单词", + "问答题": "正面", + "问答题(同时生成翻转的卡片<可选>)": "正面", + "问答题(同时生成翻转的卡片)": "正面", + "问答题(输入答案)": "正面" + }, + "CONTEXT_FIELDS": {}, + "FOLDER_DECKS": { + "this is a test": "", + "this is a test/this is a good test": "", + "文件夹1": "", + "文件夹测试1": "", + "文件夹1/文件夹2": "" + }, + "FOLDER_TAGS": { + "this is a test": "", + "this is a test/this is a good test": "", + "文件夹1": "", + "文件夹测试1": "", + "文件夹1/文件夹2": "" + }, + "Syntax": { + "Begin Note": "START", + "End Note": "END", + "Begin Inline Note": "STARTI", + "End Inline Note": "ENDI", + "Target Deck Line": "TARGET DECK", + "File Tags Line": "FILE TAGS", + "Delete Note Line": "DELETE", + "Frozen Fields Line": "FROZEN" + }, + "Defaults": { + "Scan Directory": "", + "Tag": "Obsidian_to_Anki", + "Deck": "Default", + "Scheduling Interval": 0, + "Add File Link": false, + "Add Context": false, + "CurlyCloze": false, + "CurlyCloze - Highlights to Clozes": false, + "ID Comments": true, + "Add Obsidian Tags": false, + "Use Path as Deck": false + }, + "IGNORED_FILE_GLOBS": [ + "**/*.excalidraw.md" + ] + }, + "Added Media": [], + "File Hashes": { + "this is a test/未命名.md": "ee87a91024725528940f8b162ff3799a", + "this is a test/未命名 1.md": "a08b3d4473e9a0270e96e93a32c6a4e7", + "this is a test/未命名 2.md": "55d4d3fca4b8fa9c3b968b7dbb4dc51e", + "this is a test/this is a good test/test2.md": "1a65cd97b37811e4a0ae7ef560722a22", + "README.md": "5844997ffd21e5020ecaa7670e5d942e", + "未命名 1.md": "d41d8cd98f00b204e9800998ecf8427e", + "文件夹1/文件夹2/未命名 2.md": "9ade165ed805a093b87385e0fe9dc59c", + "未命名.md": "d41d8cd98f00b204e9800998ecf8427e", + "文件夹测试1/未命名.md": "4d77d99bfd36afb8606b84487618c38b", + "未命名 2.md": "d41d8cd98f00b204e9800998ecf8427e", + "第一个文件夹/第二个文件夹/未命名.md": "807d2ff070dd2f2c66941ca2c7ebff92" + }, + "fields_dict": { + "Basic": [ + "Front", + "Back" + ], + "Basic+": [ + "Front", + "Back" + ], + "Basic++": [ + "Front", + "Back" + ], + "Basic+++": [ + "Front", + "Back" + ], + "Basic-73fde": [ + "Front", + "Back" + ], + "Cloze ALL": [ + "文字", + "背面额外" + ], + "Pot Card 2": [ + "Front", + "Back", + "Symbol1", + "Voice1", + "Symbol2", + "Voice2" + ], + "Python - Basic": [ + "Front", + "Back - Basic", + "Back - Code", + "Additional Info", + "Example", + "Version" + ], + "Python - Basic (and reversed card)": [ + "Front", + "Back", + "Additional Info", + "With Options", + "Example", + "Version" + ], + "Python - Cloze": [ + "Text", + "Example", + "Version" + ], + "UVBasic-English": [ + "英语单词", + "英美音标", + "中文释义", + "vocab简明", + "vocab扩展", + "真题原句", + "柯林斯星级", + "柯林斯解释", + "来源", + "英语发音" + ], + "单词": [ + "单词", + "音标", + "助记词", + "线索", + "词性1", + "释义1", + "词性2", + "释义2", + "发音", + "拓展" + ], + "图片遮盖": [ + "遮盖", + "图片", + "标题", + "背面额外", + "注释" + ], + "填空题": [ + "文字", + "背面额外" + ], + "红宝书": [ + "单词", + "音标", + "解释", + "红宝书", + "字源", + "不择手段背单词", + "趣味全助记", + "Audio" + ], + "问答题": [ + "正面", + "背面" + ], + "问答题(同时生成翻转的卡片<可选>)": [ + "正面", + "背面", + "添加翻转的卡片" + ], + "问答题(同时生成翻转的卡片)": [ + "正面", + "背面" + ], + "问答题(输入答案)": [ + "正面", + "背面" + ] + } +} \ No newline at end of file diff --git a/main.ts b/main.ts index 4b4c1d30..9a8bf82b 100644 --- a/main.ts +++ b/main.ts @@ -42,6 +42,7 @@ export default class MyPlugin extends Plugin { "CurlyCloze - Highlights to Clozes": false, "ID Comments": true, "Add Obsidian Tags": false, + "Use Path as Deck" : false, }, IGNORED_FILE_GLOBS: DEFAULT_IGNORED_FILE_GLOBS, } diff --git a/manifest.json b/manifest.json index e10e8a8e..44c8a6d4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { - "id": "obsidian-to-anki-plugin", + "id": "obsidian-new-to-anki-plugin", "name": "Obsidian_to_Anki", - "version": "3.6.0", + "version": "0.0.0", "minAppVersion": "0.9.20", - "description": "This is an Anki integration plugin! Designed for efficient bulk exporting.", - "author": "Pseudonium", + "description": "To help people to learn better.", + "author": "Norcx", "authorUrl": "https://github.com/Pseudonium/Obsidian_to_Anki", "isDesktopOnly": true } diff --git a/obsidian_to_anki.py b/obsidian_to_anki.py index 0fb1fb4c..8395a6c3 100644 --- a/obsidian_to_anki.py +++ b/obsidian_to_anki.py @@ -1225,7 +1225,7 @@ def setup_target_deck(self): result = App.DECK_REGEXP.search(self.file) if result is not None: self.target_deck = result.group(1) - else: + else:#todo self.target_deck = NOTE_DICT_TEMPLATE["deckName"] def setup_global_tags(self): diff --git a/package-lock.json b/package-lock.json index a2372c62..32893397 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-to-anki-plugin", - "version": "3.4.2", + "version": "3.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-to-anki-plugin", - "version": "3.4.2", + "version": "3.6.0", "license": "MIT", "dependencies": { "byte-base64": "^1.1.0", diff --git a/package.json b/package.json index 80bc301f..34f3e92a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "obsidian-to-anki-plugin", - "version": "3.6.0", - "description": "This is an Anki integration plugin! Designed for efficient bulk exporting.", + "name": "obsidian-new-to-anki-plugin", + "version": "0.0.0", + "description": "To help people to learn better.", "main": "main.js", "scripts": { "dev": "rollup --config rollup.config.js -w", diff --git a/src/file.ts b/src/file.ts index 2319d968..d0bd0325 100644 --- a/src/file.ts +++ b/src/file.ts @@ -92,8 +92,9 @@ abstract class AbstractFile { tags: string[] formatter: FormatConverter - - constructor(file_contents: string, path:string, url: string, data: FileData, file_cache: CachedMetadata) { + fullpath: string + use_path_as_deck:boolean + constructor(file_contents: string, path:string, url: string, data: FileData, file_cache: CachedMetadata, fullpath: string,use_path_as_deck:boolean) { this.data = data this.file = file_contents this.path = path @@ -101,6 +102,8 @@ abstract class AbstractFile { this.original_file = this.file this.file_cache = file_cache this.formatter = new FormatConverter(file_cache, this.data.vault_name) + this.fullpath = fullpath + this.use_path_as_deck = use_path_as_deck } setup_frozen_fields_dict() { @@ -129,8 +132,14 @@ abstract class AbstractFile { } setup_target_deck() { + if(this.use_path_as_deck){ + this.target_deck = this.fullpath.replaceAll("/","::") + } + else{ const result = this.file.match(this.data.DECK_REGEXP) this.target_deck = result ? result[1] : this.data.template["deckName"] + } + } setup_global_tags() { @@ -259,8 +268,8 @@ export class AllFile extends AbstractFile { regex_notes_to_add: AnkiConnectNote[] regex_id_indexes: number[] - constructor(file_contents: string, path:string, url: string, data: FileData, file_cache: CachedMetadata) { - super(file_contents, path, url, data, file_cache) + constructor(file_contents: string, path:string, url: string, data: FileData, file_cache: CachedMetadata,fullpath:string,use_path_as_deck:boolean) { + super(file_contents, path, url, data, file_cache, fullpath,use_path_as_deck) this.custom_regexps = data.custom_regexps } diff --git a/src/files-manager.ts b/src/files-manager.ts index fb4d35f3..95358c38 100644 --- a/src/files-manager.ts +++ b/src/files-manager.ts @@ -136,6 +136,7 @@ export class FileManager { async genAllFiles() { for (let file of this.files) { const content: string = await this.app.vault.read(file) + const fullpath: string = (file.path) const cache: CachedMetadata = this.app.metadataCache.getCache(file.path) const file_data = this.dataToFileData(file) this.ownFiles.push( @@ -144,7 +145,9 @@ export class FileManager { file.path, this.data.add_file_link ? this.getUrl(file) : "", file_data, - cache + cache, + fullpath, + this.data.use_path_as_deck ) ) } diff --git a/src/interfaces/settings-interface.ts b/src/interfaces/settings-interface.ts index dd022b0f..1157da02 100644 --- a/src/interfaces/settings-interface.ts +++ b/src/interfaces/settings-interface.ts @@ -27,7 +27,9 @@ export interface PluginSettings { "CurlyCloze": boolean, "CurlyCloze - Highlights to Clozes": boolean, "ID Comments": boolean, - "Add Obsidian Tags": boolean + "Add Obsidian Tags": boolean, + "Use Path as Deck" : boolean + }, IGNORED_FILE_GLOBS:string[] } @@ -54,6 +56,7 @@ export interface FileData { comment: boolean add_context: boolean add_obs_tags: boolean + use_path_as_deck: boolean } export interface ParsedSettings extends FileData { diff --git a/src/note.ts b/src/note.ts index 17330c31..8b838162 100644 --- a/src/note.ts +++ b/src/note.ts @@ -80,6 +80,7 @@ abstract class AbstractNote { abstract getFields(): Record parse(deck:string, url:string, frozen_fields_dict: FROZEN_FIELDS_DICT, data: FileData, context:string): AnkiConnectNoteAndID { + //delete data.template["use_path_as_deck"]; let template = JSON.parse(JSON.stringify(data.template)) template["modelName"] = this.note_type if (this.no_note_type) { diff --git a/src/setting-to-data.ts b/src/setting-to-data.ts index 62c47fd2..e1c1a8cc 100644 --- a/src/setting-to-data.ts +++ b/src/setting-to-data.ts @@ -42,6 +42,7 @@ export async function settingToData(app: App, settings: PluginSettings, fields_d result.comment = settings.Defaults["ID Comments"] result.add_context = settings.Defaults["Add Context"] result.add_obs_tags = settings.Defaults["Add Obsidian Tags"] + result.use_path_as_deck= settings.Defaults["Use Path as Deck"] result.ignored_file_globs = settings.IGNORED_FILE_GLOBS ?? []; return result diff --git a/src/settings.ts b/src/settings.ts index 08f42fe2..70a71d37 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -11,7 +11,8 @@ const defaultDescs = { "CurlyCloze": "Convert {cloze deletions} -> {{c1::cloze deletions}} on note types that have a 'Cloze' in their name.", "CurlyCloze - Highlights to Clozes": "Convert ==highlights== -> {highlights} to be processed by CurlyCloze.", "ID Comments": "Wrap note IDs in a HTML comment.", - "Add Obsidian Tags": "Interpret #tags in the fields of a note as Anki tags, removing them from the note text in Anki." + "Add Obsidian Tags": "Interpret #tags in the fields of a note as Anki tags, removing them from the note text in Anki.", + "Use Path as Deck": "Make anki's deck consistent with obsidian's folder structure" } export const DEFAULT_IGNORED_FILE_GLOBS = [ @@ -195,6 +196,9 @@ export class SettingsTab extends PluginSettingTab { if (!(plugin.settings["Defaults"].hasOwnProperty("Add Obsidian Tags"))) { plugin.settings["Defaults"]["Add Obsidian Tags"] = false } + if (!(plugin.settings["Defaults"].hasOwnProperty("Use Path as Deck"))) { + plugin.settings["Defaults"]["Use Path as Deck"] = false + } for (let key of Object.keys(plugin.settings["Defaults"])) { // To account for removal of regex setting if (key === "Regex") { From a7c36efb966f8454ecd8f81dcf6f327f1d381903 Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Sun, 14 Apr 2024 21:14:17 +0800 Subject: [PATCH 02/21] Added option to make anki's deck consistent with folder structure --- data.json | 218 -------------------------------------------- manifest.json | 8 +- obsidian_to_anki.py | 2 +- package-lock.json | 4 +- package.json | 6 +- 5 files changed, 10 insertions(+), 228 deletions(-) delete mode 100644 data.json diff --git a/data.json b/data.json deleted file mode 100644 index 12cd1c62..00000000 --- a/data.json +++ /dev/null @@ -1,218 +0,0 @@ -{ - "settings": { - "CUSTOM_REGEXPS": { - "Basic": "", - "Basic+": "", - "Basic++": "", - "Basic+++": "", - "Basic-73fde": "", - "Cloze ALL": "", - "Pot Card 2": "", - "Python - Basic": "", - "Python - Basic (and reversed card)": "", - "Python - Cloze": "", - "UVBasic-English": "", - "单词": "", - "图片遮盖": "", - "填空题": "", - "红宝书": "", - "问答题": "", - "问答题(同时生成翻转的卡片<可选>)": "", - "问答题(同时生成翻转的卡片)": "", - "问答题(输入答案)": "" - }, - "FILE_LINK_FIELDS": { - "Basic": "Front", - "Basic+": "Front", - "Basic++": "Front", - "Basic+++": "Front", - "Basic-73fde": "Front", - "Cloze ALL": "文字", - "Pot Card 2": "Front", - "Python - Basic": "Front", - "Python - Basic (and reversed card)": "Front", - "Python - Cloze": "Text", - "UVBasic-English": "英语单词", - "单词": "单词", - "图片遮盖": "遮盖", - "填空题": "文字", - "红宝书": "单词", - "问答题": "正面", - "问答题(同时生成翻转的卡片<可选>)": "正面", - "问答题(同时生成翻转的卡片)": "正面", - "问答题(输入答案)": "正面" - }, - "CONTEXT_FIELDS": {}, - "FOLDER_DECKS": { - "this is a test": "", - "this is a test/this is a good test": "", - "文件夹1": "", - "文件夹测试1": "", - "文件夹1/文件夹2": "" - }, - "FOLDER_TAGS": { - "this is a test": "", - "this is a test/this is a good test": "", - "文件夹1": "", - "文件夹测试1": "", - "文件夹1/文件夹2": "" - }, - "Syntax": { - "Begin Note": "START", - "End Note": "END", - "Begin Inline Note": "STARTI", - "End Inline Note": "ENDI", - "Target Deck Line": "TARGET DECK", - "File Tags Line": "FILE TAGS", - "Delete Note Line": "DELETE", - "Frozen Fields Line": "FROZEN" - }, - "Defaults": { - "Scan Directory": "", - "Tag": "Obsidian_to_Anki", - "Deck": "Default", - "Scheduling Interval": 0, - "Add File Link": false, - "Add Context": false, - "CurlyCloze": false, - "CurlyCloze - Highlights to Clozes": false, - "ID Comments": true, - "Add Obsidian Tags": false, - "Use Path as Deck": false - }, - "IGNORED_FILE_GLOBS": [ - "**/*.excalidraw.md" - ] - }, - "Added Media": [], - "File Hashes": { - "this is a test/未命名.md": "ee87a91024725528940f8b162ff3799a", - "this is a test/未命名 1.md": "a08b3d4473e9a0270e96e93a32c6a4e7", - "this is a test/未命名 2.md": "55d4d3fca4b8fa9c3b968b7dbb4dc51e", - "this is a test/this is a good test/test2.md": "1a65cd97b37811e4a0ae7ef560722a22", - "README.md": "5844997ffd21e5020ecaa7670e5d942e", - "未命名 1.md": "d41d8cd98f00b204e9800998ecf8427e", - "文件夹1/文件夹2/未命名 2.md": "9ade165ed805a093b87385e0fe9dc59c", - "未命名.md": "d41d8cd98f00b204e9800998ecf8427e", - "文件夹测试1/未命名.md": "4d77d99bfd36afb8606b84487618c38b", - "未命名 2.md": "d41d8cd98f00b204e9800998ecf8427e", - "第一个文件夹/第二个文件夹/未命名.md": "807d2ff070dd2f2c66941ca2c7ebff92" - }, - "fields_dict": { - "Basic": [ - "Front", - "Back" - ], - "Basic+": [ - "Front", - "Back" - ], - "Basic++": [ - "Front", - "Back" - ], - "Basic+++": [ - "Front", - "Back" - ], - "Basic-73fde": [ - "Front", - "Back" - ], - "Cloze ALL": [ - "文字", - "背面额外" - ], - "Pot Card 2": [ - "Front", - "Back", - "Symbol1", - "Voice1", - "Symbol2", - "Voice2" - ], - "Python - Basic": [ - "Front", - "Back - Basic", - "Back - Code", - "Additional Info", - "Example", - "Version" - ], - "Python - Basic (and reversed card)": [ - "Front", - "Back", - "Additional Info", - "With Options", - "Example", - "Version" - ], - "Python - Cloze": [ - "Text", - "Example", - "Version" - ], - "UVBasic-English": [ - "英语单词", - "英美音标", - "中文释义", - "vocab简明", - "vocab扩展", - "真题原句", - "柯林斯星级", - "柯林斯解释", - "来源", - "英语发音" - ], - "单词": [ - "单词", - "音标", - "助记词", - "线索", - "词性1", - "释义1", - "词性2", - "释义2", - "发音", - "拓展" - ], - "图片遮盖": [ - "遮盖", - "图片", - "标题", - "背面额外", - "注释" - ], - "填空题": [ - "文字", - "背面额外" - ], - "红宝书": [ - "单词", - "音标", - "解释", - "红宝书", - "字源", - "不择手段背单词", - "趣味全助记", - "Audio" - ], - "问答题": [ - "正面", - "背面" - ], - "问答题(同时生成翻转的卡片<可选>)": [ - "正面", - "背面", - "添加翻转的卡片" - ], - "问答题(同时生成翻转的卡片)": [ - "正面", - "背面" - ], - "问答题(输入答案)": [ - "正面", - "背面" - ] - } -} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 44c8a6d4..e10e8a8e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,10 +1,10 @@ { - "id": "obsidian-new-to-anki-plugin", + "id": "obsidian-to-anki-plugin", "name": "Obsidian_to_Anki", - "version": "0.0.0", + "version": "3.6.0", "minAppVersion": "0.9.20", - "description": "To help people to learn better.", - "author": "Norcx", + "description": "This is an Anki integration plugin! Designed for efficient bulk exporting.", + "author": "Pseudonium", "authorUrl": "https://github.com/Pseudonium/Obsidian_to_Anki", "isDesktopOnly": true } diff --git a/obsidian_to_anki.py b/obsidian_to_anki.py index 8395a6c3..0fb1fb4c 100644 --- a/obsidian_to_anki.py +++ b/obsidian_to_anki.py @@ -1225,7 +1225,7 @@ def setup_target_deck(self): result = App.DECK_REGEXP.search(self.file) if result is not None: self.target_deck = result.group(1) - else:#todo + else: self.target_deck = NOTE_DICT_TEMPLATE["deckName"] def setup_global_tags(self): diff --git a/package-lock.json b/package-lock.json index 32893397..a2372c62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-to-anki-plugin", - "version": "3.6.0", + "version": "3.4.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-to-anki-plugin", - "version": "3.6.0", + "version": "3.4.2", "license": "MIT", "dependencies": { "byte-base64": "^1.1.0", diff --git a/package.json b/package.json index 34f3e92a..80bc301f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "obsidian-new-to-anki-plugin", - "version": "0.0.0", - "description": "To help people to learn better.", + "name": "obsidian-to-anki-plugin", + "version": "3.6.0", + "description": "This is an Anki integration plugin! Designed for efficient bulk exporting.", "main": "main.js", "scripts": { "dev": "rollup --config rollup.config.js -w", From 8d4268e6784e8f44b46a917d0ce8b30517066a02 Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Sun, 14 Apr 2024 23:34:10 +0800 Subject: [PATCH 03/21] Automatically ignore notes without cards --- src/file.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/file.ts b/src/file.ts index d0bd0325..3764fa07 100644 --- a/src/file.ts +++ b/src/file.ts @@ -324,6 +324,8 @@ export class AllFile extends AbstractFile { this.data, this.data.add_context ? this.getContextAtIndex(note_match.index) : "" ) + if( Object.keys(this.frozen_fields_dict).length === 0) + continue if (parsed.identifier == null) { // Need to make sure global_tags get added parsed.note.tags.push(...this.global_tags.split(TAG_SEP)) @@ -362,6 +364,9 @@ export class AllFile extends AbstractFile { this.data, this.data.add_context ? this.getContextAtIndex(note_match.index) : "" ) + if( Object.keys(this.frozen_fields_dict).length === 0){ + continue + } if (parsed.identifier == null) { // Need to make sure global_tags get added parsed.note.tags.push(...this.global_tags.split(TAG_SEP)) @@ -400,6 +405,9 @@ export class AllFile extends AbstractFile { this.data, this.data.add_context ? this.getContextAtIndex(match.index) : "" ) + if( Object.keys(this.frozen_fields_dict).length === 0){ + continue + } if (search_id) { if (!(this.data.EXISTING_IDS.includes(parsed.identifier))) { if (parsed.identifier == CLOZE_ERROR) { From 9b5b3060d162d0fe9b98c6b68cb0376f2ef4317f Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Tue, 16 Apr 2024 01:09:16 +0800 Subject: [PATCH 04/21] Now it won't create an empty deck --- .gitignore | 2 +- data.json | 223 +++++++++++++++++++++++++++++++++++++++++++ src/file.ts | 10 +- src/files-manager.ts | 2 + 4 files changed, 227 insertions(+), 10 deletions(-) create mode 100644 data.json diff --git a/.gitignore b/.gitignore index 4969a45a..b213bda5 100644 --- a/.gitignore +++ b/.gitignore @@ -280,4 +280,4 @@ main.js tests/test_config/* tests/test_vault/* tests/specs_gen/* -tests/test_outputs/* +tests/test_outputs/* \ No newline at end of file diff --git a/data.json b/data.json new file mode 100644 index 00000000..34db13b9 --- /dev/null +++ b/data.json @@ -0,0 +1,223 @@ +{ + "settings": { + "CUSTOM_REGEXPS": { + "Basic": "((?:[^\\n][\\n]?)+) #flashcard ?\\n*((?:\\n(?:^.{1,3}$|^.{4}(?)": "", + "问答题(同时生成翻转的卡片)": "", + "问答题(输入答案)": "" + }, + "FILE_LINK_FIELDS": { + "Basic": "Front", + "Basic+": "Front", + "Basic++": "Front", + "Basic+++": "Front", + "Basic-73fde": "Front", + "Cloze ALL": "文字", + "Pot Card 2": "Front", + "Python - Basic": "Front", + "Python - Basic (and reversed card)": "Front", + "Python - Cloze": "Text", + "UVBasic-English": "英语单词", + "单词": "单词", + "图片遮盖": "遮盖", + "填空题": "文字", + "红宝书": "单词", + "问答题": "正面", + "问答题(同时生成翻转的卡片<可选>)": "正面", + "问答题(同时生成翻转的卡片)": "正面", + "问答题(输入答案)": "正面" + }, + "CONTEXT_FIELDS": {}, + "FOLDER_DECKS": { + "第一个文件夹": "", + "第一个文件夹/第二个文件夹": "" + }, + "FOLDER_TAGS": { + "第一个文件夹": "", + "第一个文件夹/第二个文件夹": "" + }, + "Syntax": { + "Begin Note": "START", + "End Note": "END", + "Begin Inline Note": "STARTI", + "End Inline Note": "ENDI", + "Target Deck Line": "TARGET DECK", + "File Tags Line": "FILE TAGS", + "Delete Note Line": "DELETE", + "Frozen Fields Line": "FROZEN" + }, + "Defaults": { + "Scan Directory": "", + "Tag": "Obsidian_to_Anki", + "Deck": "Default", + "Scheduling Interval": 0, + "Add File Link": false, + "Add Context": false, + "CurlyCloze": false, + "CurlyCloze - Highlights to Clozes": false, + "ID Comments": true, + "Add Obsidian Tags": false, + "Use Path as Deck": true + }, + "IGNORED_FILE_GLOBS": [ + "**/*.excalidraw.md" + ] + }, + "Added Media": [], + "File Hashes": { + "未命名 2.md": "30a44ea90cb104d9b16dda3826232784", + "第一个文件夹/第二个文件夹/未命名.md": "ef1e094f5b366fe563e71c1f6bcd141c", + "未命名 1.md": "4c811787fb4a175e57da923063c1e41c", + "README.md": "5844997ffd21e5020ecaa7670e5d942e", + "读一本好书.md": "d41d8cd98f00b204e9800998ecf8427e", + "读书.md": "d41d8cd98f00b204e9800998ecf8427e", + "你好.md": "d41d8cd98f00b204e9800998ecf8427e", + "你好呀.md": "09639afc110da5e7033d4e6ce12147ff", + "未命名.md": "d41d8cd98f00b204e9800998ecf8427e", + "第一个文件夹/读书.md": "d41d8cd98f00b204e9800998ecf8427e", + "第一个文件夹/读一本好书.md": "2bc012e3b6e73af53f1e2254e494d7d2", + "第一个文件夹/第二个文件夹/你好呀.md": "09639afc110da5e7033d4e6ce12147ff", + "第一个文件夹/第二个文件夹/你好.md": "d41d8cd98f00b204e9800998ecf8427e", + "有笔记但是没有内容.md": "1b72193b17c8b5c77b84a045b19796b7", + "什么都没有.md": "2228e977ebea8966e27929f43e39cb67", + "未命名 4.md": "295a6be3b2f9283e4d143f2dc27d7ff2", + "你是谁.md": "7ce5d9b5499bf82ca585cd0556562db2", + "要成功了.md": "9b591dfa7f54ba2c213a127b82445566", + "破案吧.md": "03e25ab08d38fd6ea0c97b27ad4a4b4a", + "成功.md": "bcab17d6d9aa24ec021d86219ba80275", + "这次必须成功.md": "20465dbf32a76306b96b98c76694b3f3", + "这个文件不会出现.md": "7fb85ce0404d939ba908e343e853c173" + }, + "fields_dict": { + "Basic": [ + "Front", + "Back" + ], + "Basic+": [ + "Front", + "Back" + ], + "Basic++": [ + "Front", + "Back" + ], + "Basic+++": [ + "Front", + "Back" + ], + "Basic-73fde": [ + "Front", + "Back" + ], + "Cloze ALL": [ + "文字", + "背面额外" + ], + "Pot Card 2": [ + "Front", + "Back", + "Symbol1", + "Voice1", + "Symbol2", + "Voice2" + ], + "Python - Basic": [ + "Front", + "Back - Basic", + "Back - Code", + "Additional Info", + "Example", + "Version" + ], + "Python - Basic (and reversed card)": [ + "Front", + "Back", + "Additional Info", + "With Options", + "Example", + "Version" + ], + "Python - Cloze": [ + "Text", + "Example", + "Version" + ], + "UVBasic-English": [ + "英语单词", + "英美音标", + "中文释义", + "vocab简明", + "vocab扩展", + "真题原句", + "柯林斯星级", + "柯林斯解释", + "来源", + "英语发音" + ], + "单词": [ + "单词", + "音标", + "助记词", + "线索", + "词性1", + "释义1", + "词性2", + "释义2", + "发音", + "拓展" + ], + "图片遮盖": [ + "遮盖", + "图片", + "标题", + "背面额外", + "注释" + ], + "填空题": [ + "文字", + "背面额外" + ], + "红宝书": [ + "单词", + "音标", + "解释", + "红宝书", + "字源", + "不择手段背单词", + "趣味全助记", + "Audio" + ], + "问答题": [ + "正面", + "背面" + ], + "问答题(同时生成翻转的卡片<可选>)": [ + "正面", + "背面", + "添加翻转的卡片" + ], + "问答题(同时生成翻转的卡片)": [ + "正面", + "背面" + ], + "问答题(输入答案)": [ + "正面", + "背面" + ] + } +} \ No newline at end of file diff --git a/src/file.ts b/src/file.ts index 3764fa07..0fb544ab 100644 --- a/src/file.ts +++ b/src/file.ts @@ -1,5 +1,5 @@ /*Performing plugin operations on markdown file contents*/ - +import { appendFile } from 'fs'; import { FROZEN_FIELDS_DICT } from './interfaces/field-interface' import { AnkiConnectNote, AnkiConnectNoteAndID } from './interfaces/note-interface' import { FileData } from './interfaces/settings-interface' @@ -324,8 +324,6 @@ export class AllFile extends AbstractFile { this.data, this.data.add_context ? this.getContextAtIndex(note_match.index) : "" ) - if( Object.keys(this.frozen_fields_dict).length === 0) - continue if (parsed.identifier == null) { // Need to make sure global_tags get added parsed.note.tags.push(...this.global_tags.split(TAG_SEP)) @@ -364,9 +362,6 @@ export class AllFile extends AbstractFile { this.data, this.data.add_context ? this.getContextAtIndex(note_match.index) : "" ) - if( Object.keys(this.frozen_fields_dict).length === 0){ - continue - } if (parsed.identifier == null) { // Need to make sure global_tags get added parsed.note.tags.push(...this.global_tags.split(TAG_SEP)) @@ -405,9 +400,6 @@ export class AllFile extends AbstractFile { this.data, this.data.add_context ? this.getContextAtIndex(match.index) : "" ) - if( Object.keys(this.frozen_fields_dict).length === 0){ - continue - } if (search_id) { if (!(this.data.EXISTING_IDS.includes(parsed.identifier))) { if (parsed.identifier == CLOZE_ERROR) { diff --git a/src/files-manager.ts b/src/files-manager.ts index 95358c38..e032aea6 100644 --- a/src/files-manager.ts +++ b/src/files-manager.ts @@ -309,6 +309,8 @@ export class FileManager { let temp: AnkiConnect.AnkiConnectRequest[] = [] console.info("Requesting cards to be moved to target deck...") for (let file of this.ownFiles) { + if (file.regex_id_indexes.length + file.inline_id_indexes.length === 0) + continue temp.push(file.getChangeDecks()) } requests.push(AnkiConnect.multi(temp)) From 615336041e083348d54895690007f62296f4ab58 Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Tue, 16 Apr 2024 01:14:08 +0800 Subject: [PATCH 05/21] Now you can optionally send notes to the corresponding deck based on the path of the file. For example, the card inside /path/folder1/test.md will be sent to a deck like this: path::folder1::test.md And it will automatically skip files without cards , so it won't create an empty deck. --- src/file.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/file.ts b/src/file.ts index 0fb544ab..3d4d1627 100644 --- a/src/file.ts +++ b/src/file.ts @@ -1,5 +1,4 @@ /*Performing plugin operations on markdown file contents*/ -import { appendFile } from 'fs'; import { FROZEN_FIELDS_DICT } from './interfaces/field-interface' import { AnkiConnectNote, AnkiConnectNoteAndID } from './interfaces/note-interface' import { FileData } from './interfaces/settings-interface' From 171349f763ef22f7ba92779aebdfd2a758450ea0 Mon Sep 17 00:00:00 2001 From: norcx <130429072+norcx@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:51:49 +0800 Subject: [PATCH 06/21] Delete data.json --- data.json | 223 ------------------------------------------------------ 1 file changed, 223 deletions(-) delete mode 100644 data.json diff --git a/data.json b/data.json deleted file mode 100644 index 34db13b9..00000000 --- a/data.json +++ /dev/null @@ -1,223 +0,0 @@ -{ - "settings": { - "CUSTOM_REGEXPS": { - "Basic": "((?:[^\\n][\\n]?)+) #flashcard ?\\n*((?:\\n(?:^.{1,3}$|^.{4}(?)": "", - "问答题(同时生成翻转的卡片)": "", - "问答题(输入答案)": "" - }, - "FILE_LINK_FIELDS": { - "Basic": "Front", - "Basic+": "Front", - "Basic++": "Front", - "Basic+++": "Front", - "Basic-73fde": "Front", - "Cloze ALL": "文字", - "Pot Card 2": "Front", - "Python - Basic": "Front", - "Python - Basic (and reversed card)": "Front", - "Python - Cloze": "Text", - "UVBasic-English": "英语单词", - "单词": "单词", - "图片遮盖": "遮盖", - "填空题": "文字", - "红宝书": "单词", - "问答题": "正面", - "问答题(同时生成翻转的卡片<可选>)": "正面", - "问答题(同时生成翻转的卡片)": "正面", - "问答题(输入答案)": "正面" - }, - "CONTEXT_FIELDS": {}, - "FOLDER_DECKS": { - "第一个文件夹": "", - "第一个文件夹/第二个文件夹": "" - }, - "FOLDER_TAGS": { - "第一个文件夹": "", - "第一个文件夹/第二个文件夹": "" - }, - "Syntax": { - "Begin Note": "START", - "End Note": "END", - "Begin Inline Note": "STARTI", - "End Inline Note": "ENDI", - "Target Deck Line": "TARGET DECK", - "File Tags Line": "FILE TAGS", - "Delete Note Line": "DELETE", - "Frozen Fields Line": "FROZEN" - }, - "Defaults": { - "Scan Directory": "", - "Tag": "Obsidian_to_Anki", - "Deck": "Default", - "Scheduling Interval": 0, - "Add File Link": false, - "Add Context": false, - "CurlyCloze": false, - "CurlyCloze - Highlights to Clozes": false, - "ID Comments": true, - "Add Obsidian Tags": false, - "Use Path as Deck": true - }, - "IGNORED_FILE_GLOBS": [ - "**/*.excalidraw.md" - ] - }, - "Added Media": [], - "File Hashes": { - "未命名 2.md": "30a44ea90cb104d9b16dda3826232784", - "第一个文件夹/第二个文件夹/未命名.md": "ef1e094f5b366fe563e71c1f6bcd141c", - "未命名 1.md": "4c811787fb4a175e57da923063c1e41c", - "README.md": "5844997ffd21e5020ecaa7670e5d942e", - "读一本好书.md": "d41d8cd98f00b204e9800998ecf8427e", - "读书.md": "d41d8cd98f00b204e9800998ecf8427e", - "你好.md": "d41d8cd98f00b204e9800998ecf8427e", - "你好呀.md": "09639afc110da5e7033d4e6ce12147ff", - "未命名.md": "d41d8cd98f00b204e9800998ecf8427e", - "第一个文件夹/读书.md": "d41d8cd98f00b204e9800998ecf8427e", - "第一个文件夹/读一本好书.md": "2bc012e3b6e73af53f1e2254e494d7d2", - "第一个文件夹/第二个文件夹/你好呀.md": "09639afc110da5e7033d4e6ce12147ff", - "第一个文件夹/第二个文件夹/你好.md": "d41d8cd98f00b204e9800998ecf8427e", - "有笔记但是没有内容.md": "1b72193b17c8b5c77b84a045b19796b7", - "什么都没有.md": "2228e977ebea8966e27929f43e39cb67", - "未命名 4.md": "295a6be3b2f9283e4d143f2dc27d7ff2", - "你是谁.md": "7ce5d9b5499bf82ca585cd0556562db2", - "要成功了.md": "9b591dfa7f54ba2c213a127b82445566", - "破案吧.md": "03e25ab08d38fd6ea0c97b27ad4a4b4a", - "成功.md": "bcab17d6d9aa24ec021d86219ba80275", - "这次必须成功.md": "20465dbf32a76306b96b98c76694b3f3", - "这个文件不会出现.md": "7fb85ce0404d939ba908e343e853c173" - }, - "fields_dict": { - "Basic": [ - "Front", - "Back" - ], - "Basic+": [ - "Front", - "Back" - ], - "Basic++": [ - "Front", - "Back" - ], - "Basic+++": [ - "Front", - "Back" - ], - "Basic-73fde": [ - "Front", - "Back" - ], - "Cloze ALL": [ - "文字", - "背面额外" - ], - "Pot Card 2": [ - "Front", - "Back", - "Symbol1", - "Voice1", - "Symbol2", - "Voice2" - ], - "Python - Basic": [ - "Front", - "Back - Basic", - "Back - Code", - "Additional Info", - "Example", - "Version" - ], - "Python - Basic (and reversed card)": [ - "Front", - "Back", - "Additional Info", - "With Options", - "Example", - "Version" - ], - "Python - Cloze": [ - "Text", - "Example", - "Version" - ], - "UVBasic-English": [ - "英语单词", - "英美音标", - "中文释义", - "vocab简明", - "vocab扩展", - "真题原句", - "柯林斯星级", - "柯林斯解释", - "来源", - "英语发音" - ], - "单词": [ - "单词", - "音标", - "助记词", - "线索", - "词性1", - "释义1", - "词性2", - "释义2", - "发音", - "拓展" - ], - "图片遮盖": [ - "遮盖", - "图片", - "标题", - "背面额外", - "注释" - ], - "填空题": [ - "文字", - "背面额外" - ], - "红宝书": [ - "单词", - "音标", - "解释", - "红宝书", - "字源", - "不择手段背单词", - "趣味全助记", - "Audio" - ], - "问答题": [ - "正面", - "背面" - ], - "问答题(同时生成翻转的卡片<可选>)": [ - "正面", - "背面", - "添加翻转的卡片" - ], - "问答题(同时生成翻转的卡片)": [ - "正面", - "背面" - ], - "问答题(输入答案)": [ - "正面", - "背面" - ] - } -} \ No newline at end of file From 3221f63e0db2294f1ed8f062daedbac21e63cb44 Mon Sep 17 00:00:00 2001 From: norcx <130429072+norcx@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:53:34 +0800 Subject: [PATCH 07/21] Delete .gitignore --- .gitignore | 283 ----------------------------------------------------- 1 file changed, 283 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b213bda5..00000000 --- a/.gitignore +++ /dev/null @@ -1,283 +0,0 @@ -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -pip-wheel-metadata/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -.python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# Created by https://www.toptal.com/developers/gitignore/api/node -# Edit at https://www.toptal.com/developers/gitignore?templates=node - -### Node ### -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# TypeScript v1 declaration files -typings/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env -.env.test -.env*.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next - -# Nuxt.js build / generate output -.nuxt -dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# End of https://www.toptal.com/developers/gitignore/api/node - -# Docker project generated files to ignore -# if you want to ignore files created by your editor/tools, -# please consider a global .gitignore https://help.github.com/articles/ignoring-files -# https://github.com/atlassian/docker/blob/master/.gitignore -.vagrant* -bin -docker/docker -.*.swp -a.out -*.orig -build_src -.flymake* -.idea -.DS_Store -docs/_build -docs/_static -docs/_templates -.gopath/ -.dotcloud -*.test -bundles/ -.hg/ -.git/ -vendor/pkg/ -pyenv -Vagrantfile - -*.cid - -# Obsidian-to-Anki plugin Specifc -# Complied Plugin Outputs -main.js - -tests/test_config/* -tests/test_vault/* -tests/specs_gen/* -tests/test_outputs/* \ No newline at end of file From c7c71a39ec57133087acc202cf4e75d4216602e7 Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Wed, 17 Apr 2024 13:51:28 +0800 Subject: [PATCH 08/21] good --- .gitignore | 4 +- data.json | 157 ++--------------------------------------------------- 2 files changed, 9 insertions(+), 152 deletions(-) diff --git a/.gitignore b/.gitignore index b213bda5..42ca261d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# data.json need save +./data.json # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -280,4 +282,4 @@ main.js tests/test_config/* tests/test_vault/* tests/specs_gen/* -tests/test_outputs/* \ No newline at end of file +tests/test_outputs/* diff --git a/data.json b/data.json index 34db13b9..5ff263e1 100644 --- a/data.json +++ b/data.json @@ -1,7 +1,7 @@ { "settings": { "CUSTOM_REGEXPS": { - "Basic": "((?:[^\\n][\\n]?)+) #flashcard ?\\n*((?:\\n(?:^.{1,3}$|^.{4}(?)": [ - "正面", - "背面", - "添加翻转的卡片" - ], - "问答题(同时生成翻转的卡片)": [ - "正面", - "背面" - ], - "问答题(输入答案)": [ - "正面", - "背面" - ] - } + "File Hashes": {}, + "fields_dict": {} } \ No newline at end of file From 968c700d5f47fd4c25e8fa366896621ee2341898 Mon Sep 17 00:00:00 2001 From: norcx <2012554655@qq.com> Date: Fri, 19 Apr 2024 09:51:25 +0800 Subject: [PATCH 09/21] Added link to jump to obsidian block from anki --- data.json | 154 +++++++++++++++++++++++++-- main.ts | 1 + src/file.ts | 27 ++++- src/files-manager.ts | 5 +- src/interfaces/settings-interface.ts | 4 +- src/setting-to-data.ts | 1 + src/settings.ts | 6 +- 7 files changed, 185 insertions(+), 13 deletions(-) diff --git a/data.json b/data.json index 5ff263e1..6f2a7366 100644 --- a/data.json +++ b/data.json @@ -1,7 +1,7 @@ { "settings": { "CUSTOM_REGEXPS": { - "Basic": "", + "Basic": "((?:[^\\n][\\n]?)+) #flashcard ?\\n*((?:\\n(?:^.{1,3}$|^.{4}(?)": [ + "正面", + "背面", + "添加翻转的卡片" + ], + "问答题(同时生成翻转的卡片)": [ + "正面", + "背面" + ], + "问答题(输入答案)": [ + "正面", + "背面" + ] + } } \ No newline at end of file diff --git a/main.ts b/main.ts index 9a8bf82b..666c494d 100644 --- a/main.ts +++ b/main.ts @@ -43,6 +43,7 @@ export default class MyPlugin extends Plugin { "ID Comments": true, "Add Obsidian Tags": false, "Use Path as Deck" : false, + "Add Card link": false }, IGNORED_FILE_GLOBS: DEFAULT_IGNORED_FILE_GLOBS, } diff --git a/src/file.ts b/src/file.ts index 3d4d1627..f9d48a34 100644 --- a/src/file.ts +++ b/src/file.ts @@ -10,6 +10,7 @@ import { FormatConverter } from './format' import { CachedMetadata, HeadingCache } from 'obsidian' const double_regexp: RegExp = /(?:\r\n|\r|\n)((?:\r\n|\r|\n)(?:" @@ -470,7 +473,7 @@ export class AllFile extends AbstractFile { (id_position: number, index: number) => { const identifier: number | null = this.note_ids[index] if (identifier) { - normal_inserts.push([id_position, id_to_str(identifier, false, this.data.comment)]) + normal_inserts.push([id_position, id_to_str(identifier, false, this.data.comment,this.data.add_card_link)]) } } ) @@ -479,7 +482,7 @@ export class AllFile extends AbstractFile { (id_position: number, index: number) => { const identifier: number | null = this.note_ids[index + this.notes_to_add.length] //Since regular then inline if (identifier) { - inline_inserts.push([id_position, id_to_str(identifier, true, this.data.comment)]) + inline_inserts.push([id_position, id_to_str(identifier, true, this.data.comment,this.data.add_card_link)]) } } ) @@ -488,7 +491,7 @@ export class AllFile extends AbstractFile { (id_position: number, index: number) => { const identifier: number | null = this.note_ids[index + this.notes_to_add.length + this.inline_notes_to_add.length] // Since regular then inline then regex if (identifier) { - regex_inserts.push([id_position, "\n" + id_to_str(identifier, false, this.data.comment)]) + regex_inserts.push([id_position, "\n" + id_to_str(identifier, false, this.data.comment,this.data.add_card_link)]) } } ) diff --git a/src/files-manager.ts b/src/files-manager.ts index c8001170..4a6b2ca3 100644 --- a/src/files-manager.ts +++ b/src/files-manager.ts @@ -143,7 +143,7 @@ export class FileManager { new AllFile( content, file.path, - this.data.add_file_link ? this.getUrl(file) : "", + this.data.add_file_link ? (this.data.add_card_link ? this.getUrl(file).slice(0,-3)+"%23%5E" :this.getUrl(file)) : "", file_data, cache, fullpath, diff --git a/src/note.ts b/src/note.ts index 8b838162..2c4eaa8b 100644 --- a/src/note.ts +++ b/src/note.ts @@ -10,7 +10,7 @@ import { FileData } from './interfaces/settings-interface' const TAG_PREFIX:string = "Tags: " export const TAG_SEP:string = " " -export const ID_REGEXP_STR: string = String.raw`\n?(?: