Skip to content

Commit

Permalink
add toggle to settings for prepending file link line break
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcoleanderson committed Feb 13, 2024
1 parent ce623ed commit 90f24fd
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] += '<a href="' + url + '" class="obsidian-link">Obsidian</a>'
format_note_with_url(note: AnkiConnectNote, url: string, field: string, prependLineBreak: boolean): void {
if (prependLineBreak) {
note.fields[field] += '<br>'
}
note.fields[field] += '<a href="' + url + '" class="obsidian-link">Obsidian</a>'
}

format_note_with_frozen_fields(note: AnkiConnectNote, frozen_fields_dict: Record<string, Record<string, string>>): void {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/settings-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/setting-to-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down

0 comments on commit 90f24fd

Please sign in to comment.