From 90f24fdd9d6dc86ebd60726af34a30e481ac4923 Mon Sep 17 00:00:00 2001 From: mattcoleanderson Date: Tue, 13 Feb 2024 17:59:13 -0600 Subject: [PATCH] add toggle to settings for prepending file link line break --- src/format.ts | 7 +++++-- src/interfaces/settings-interface.ts | 2 ++ src/note.ts | 4 ++-- src/setting-to-data.ts | 1 + src/settings.ts | 1 + 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/format.ts b/src/format.ts index e1fd5ff7..ecab3779 100644 --- a/src/format.ts +++ b/src/format.ts @@ -57,8 +57,11 @@ export class FormatConverter { return "obsidian://open?vault=" + encodeURIComponent(this.vault_name) + String.raw`&file=` + encodeURIComponent(link) } - format_note_with_url(note: AnkiConnectNote, url: string, field: string): void { - note.fields[field] += 'Obsidian' + format_note_with_url(note: AnkiConnectNote, url: string, field: string, prependLineBreak: boolean): void { + if (prependLineBreak) { + note.fields[field] += '
' + } + note.fields[field] += 'Obsidian' } format_note_with_frozen_fields(note: AnkiConnectNote, frozen_fields_dict: Record>): void { diff --git a/src/interfaces/settings-interface.ts b/src/interfaces/settings-interface.ts index dd022b0f..38953c51 100644 --- a/src/interfaces/settings-interface.ts +++ b/src/interfaces/settings-interface.ts @@ -23,6 +23,7 @@ export interface PluginSettings { "Deck": string, "Scheduling Interval": number "Add File Link": boolean, + "Prepend File Link Line Break": boolean, "Add Context": boolean, "CurlyCloze": boolean, "CurlyCloze - Highlights to Clozes": boolean, @@ -52,6 +53,7 @@ export interface FileData { curly_cloze: boolean highlights_to_cloze: boolean comment: boolean + prepend_file_link_line_break: boolean add_context: boolean add_obs_tags: boolean } diff --git a/src/note.ts b/src/note.ts index 17330c31..187f3f79 100644 --- a/src/note.ts +++ b/src/note.ts @@ -88,7 +88,7 @@ abstract class AbstractNote { template["fields"] = this.getFields() const file_link_fields = data.file_link_fields if (url) { - this.formatter.format_note_with_url(template, url, file_link_fields[this.note_type]) + this.formatter.format_note_with_url(template, url, file_link_fields[this.note_type], data.prepend_file_link_line_break) } if (Object.keys(frozen_fields_dict).length) { this.formatter.format_note_with_frozen_fields(template, frozen_fields_dict) @@ -290,7 +290,7 @@ export class RegexNote { template["fields"] = this.getFields() const file_link_fields = data.file_link_fields if (url) { - this.formatter.format_note_with_url(template, url, file_link_fields[this.note_type]) + this.formatter.format_note_with_url(template, url, file_link_fields[this.note_type], data.prepend_file_link_line_break) } if (Object.keys(frozen_fields_dict).length) { this.formatter.format_note_with_frozen_fields(template, frozen_fields_dict) diff --git a/src/setting-to-data.ts b/src/setting-to-data.ts index 62c47fd2..a19d1323 100644 --- a/src/setting-to-data.ts +++ b/src/setting-to-data.ts @@ -39,6 +39,7 @@ export async function settingToData(app: App, settings: PluginSettings, fields_d result.curly_cloze = settings.Defaults.CurlyCloze result.highlights_to_cloze = settings.Defaults["CurlyCloze - Highlights to Clozes"] result.add_file_link = settings.Defaults["Add File Link"] + result.prepend_file_link_line_break = settings.Defaults["Prepend File Link Line Break"] result.comment = settings.Defaults["ID Comments"] result.add_context = settings.Defaults["Add Context"] result.add_obs_tags = settings.Defaults["Add Obsidian Tags"] diff --git a/src/settings.ts b/src/settings.ts index 08f42fe2..9a6cf3de 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -7,6 +7,7 @@ const defaultDescs = { "Deck": "The deck the plugin adds cards to if TARGET DECK is not specified in the file.", "Scheduling Interval": "The time, in minutes, between automatic scans of the vault. Set this to 0 to disable automatic scanning.", "Add File Link": "Append a link to the file that generated the flashcard on the field specified in the table.", + "Prepend File Link Line Break": "Prepends a line break to the File Link field. This toggle defaults to true to preserve the historically expected affect of this field. Toggling false will not update existing flashcards, only newly generated ones.", "Add Context": "Append 'context' for the card, in the form of path > heading > heading etc, to the field specified in the table.", "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.",