From 4ba105fc75ac8ade9d59e08cee12262243b49011 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 27 Dec 2024 18:08:48 -0800 Subject: [PATCH 1/4] Remove the last
tag that appears in LSB verses. --- src/verse/BaseVerseFormatter.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/verse/BaseVerseFormatter.ts b/src/verse/BaseVerseFormatter.ts index a5809be..1b8d4e3 100644 --- a/src/verse/BaseVerseFormatter.ts +++ b/src/verse/BaseVerseFormatter.ts @@ -53,17 +53,19 @@ export abstract class BaseVerseFormatter { } else { text = '' } - this.verses.forEach((verse) => { + this.verses.forEach((verse, index) => { + let singleVerseText = verse.text.trim() + if ( + index === this.verses!.length - 1 && + singleVerseText.endsWith('
') // Remove the last
tag that appears in LSB verses. + ) { + singleVerseText = singleVerseText.slice(0, -5) + } const verseNumberFormatted = this.formatVerseNumber(verse.verse) if (this.settings?.verseFormatting === BibleVerseFormat.Paragraph) { - text += - ' ' + verseNumberFormatted + verse.text.trim().replaceAll('\n', ' ') + text += ' ' + verseNumberFormatted + singleVerseText.replaceAll('\n', ' ') } else { - text += - '> ' + - verseNumberFormatted + - verse.text.trim().replace(/\r\n|\n|\r/g, ' ') + - '\n' // Remove extraneous line breaks in KJV verses. + text += '> ' + verseNumberFormatted + singleVerseText.replace(/\r\n|\n|\r/g, ' ') + '\n' // Remove extraneous line breaks in KJV verses. } }) console.debug('text', text) From 85287ff2d118a5135a5724f2948467ee84b0adc8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 28 Dec 2024 12:27:51 -0800 Subject: [PATCH 2/4] Add toggle command for Bible Icon Prefix setting --- src/data/constants.ts | 2 +- src/main.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/data/constants.ts b/src/data/constants.ts index a85641a..c88ebe2 100644 --- a/src/data/constants.ts +++ b/src/data/constants.ts @@ -61,7 +61,7 @@ export const DEFAULT_SETTINGS: BibleReferencePluginSettings = { bookBacklinking: OutgoingLinkPositionEnum.None, chapterBacklinking: OutgoingLinkPositionEnum.None, bibleVersionStatusIndicator: BibleVersionNameLengthEnum.Short, - displayBibleIconPrefixAtHeader: true, + displayBibleIconPrefixAtHeader: true } export const API_WAITING_LABEL = 'Loading...' diff --git a/src/main.ts b/src/main.ts index 657eb6e..959b4ea 100644 --- a/src/main.ts +++ b/src/main.ts @@ -60,6 +60,9 @@ export default class BibleReferencePlugin extends Plugin { this.addVerseOfDayInsertCommand() this.addVerseOfDayNoticeCommand() + // toggle bible icon prefix + this.toggleBibleIconPrefix() + this.initStatusBarIndicator() EventStats.logRecord(this.settings.optOutToEvents) } @@ -154,6 +157,19 @@ export default class BibleReferencePlugin extends Plugin { }) } + // create a hotkey that will toggle the "Show Bible Icon Prefix" setting called: "setUpBibleIconPrefixToggle" from the BibleReferenceSettingTab class + + private toggleBibleIconPrefix() { + this.addCommand({ + id: 'toggle-bible-icon-prefix', + name: 'Toggle Bible Icon Prefix', + callback: () => { + this.settings.displayBibleIconPrefixAtHeader = !this.settings.displayBibleIconPrefixAtHeader + this.saveSettings() + }, + }) + } + private addRibbonButton(): void { // https://lucide.dev/icons/?search=book // Obsidian use Lucide Icons From 1b0a22748640529f947bb435af30a6d682031f8e Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 28 Dec 2024 13:03:29 -0800 Subject: [PATCH 3/4] accidently left in added comment --- src/main.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 959b4ea..16d2401 100644 --- a/src/main.ts +++ b/src/main.ts @@ -157,8 +157,6 @@ export default class BibleReferencePlugin extends Plugin { }) } - // create a hotkey that will toggle the "Show Bible Icon Prefix" setting called: "setUpBibleIconPrefixToggle" from the BibleReferenceSettingTab class - private toggleBibleIconPrefix() { this.addCommand({ id: 'toggle-bible-icon-prefix', From d1151c6aee1279dd87d46e7c01600840e8f4b5aa Mon Sep 17 00:00:00 2001 From: Daniel Agafonov Date: Sat, 28 Dec 2024 13:48:51 -0800 Subject: [PATCH 4/4] Add collapsible verses feature with options for default behavior (issue 244) --- src/data/CollapsibleVerses.ts | 20 +++++++++++++++ src/data/constants.ts | 5 ++-- src/ui/BibleReferenceSettingTab.ts | 41 ++++++++++++++++-------------- src/verse/BaseVerseFormatter.ts | 13 ++++++++-- 4 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 src/data/CollapsibleVerses.ts diff --git a/src/data/CollapsibleVerses.ts b/src/data/CollapsibleVerses.ts new file mode 100644 index 0000000..66d3e59 --- /dev/null +++ b/src/data/CollapsibleVerses.ts @@ -0,0 +1,20 @@ +export enum CollapsibleVerses { + Plus = '+', + Minus = '-', + None = 'None' +} + +export const CollapsibleVersesCollection = [ + { + name: CollapsibleVerses.Plus, + description: 'Plus', + }, + { + name: CollapsibleVerses.Minus, + description: 'Minus', + }, + { + name: CollapsibleVerses.None, + description: 'None', + }, +] diff --git a/src/data/constants.ts b/src/data/constants.ts index c88ebe2..2be071a 100644 --- a/src/data/constants.ts +++ b/src/data/constants.ts @@ -2,6 +2,7 @@ import { DEFAULT_BIBLE_VERSION } from './BibleVersionCollection' import { BibleVerseReferenceLinkPosition } from './BibleVerseReferenceLinkPosition' import { BibleVerseFormat } from './BibleVerseFormat' import { BibleVerseNumberFormat } from './BibleVerseNumberFormat' +import { CollapsibleVerses } from './CollapsibleVerses' export const APP_NAMING = { appName: 'Bible Reference', @@ -28,7 +29,7 @@ export interface BibleReferencePluginSettings { referenceLinkPosition?: BibleVerseReferenceLinkPosition verseFormatting?: BibleVerseFormat verseNumberFormatting?: BibleVerseNumberFormat - collapsibleVerses?: boolean // this is binging to displayBibleIconPrefixAtHeader option + collapsibleVerses?: CollapsibleVerses // this is binging to displayBibleIconPrefixAtHeader option enableHyperlinking?: boolean showVerseTranslation?: boolean bookTagging?: boolean @@ -51,7 +52,7 @@ export const DEFAULT_SETTINGS: BibleReferencePluginSettings = { referenceLinkPosition: BibleVerseReferenceLinkPosition.Header, verseFormatting: BibleVerseFormat.SingleLine, verseNumberFormatting: BibleVerseNumberFormat.Period, - collapsibleVerses: false, + collapsibleVerses: CollapsibleVerses.Plus, enableHyperlinking: true, showVerseTranslation: true, bookTagging: false, diff --git a/src/ui/BibleReferenceSettingTab.ts b/src/ui/BibleReferenceSettingTab.ts index 5bf95b3..20f7788 100644 --- a/src/ui/BibleReferenceSettingTab.ts +++ b/src/ui/BibleReferenceSettingTab.ts @@ -23,6 +23,10 @@ import { BibleVerseNumberFormat, BibleVerseNumberFormatCollection, } from '../data/BibleVerseNumberFormat' +import { + CollapsibleVerses, + CollapsibleVersesCollection, +} from '../data/CollapsibleVerses' import { BibleAPISourceCollection } from '../data/BibleApiSourceCollection' import { EventStats } from '../provider/EventStats' import { @@ -61,7 +65,7 @@ export class BibleReferenceSettingTab extends PluginSettingTab { this.setUpVerseFormatOptions() this.setUpVerseNumberFormatOptions() this.setUpBibleIconPrefixToggle() - this.setUpCollapsibleToggle() + this.setUpCollapsibleOptions() this.setUpStatusIndicationOptions() this.containerEl.createEl('h2', { text: 'Others' }) this.setUpExpertSettings() @@ -422,28 +426,27 @@ Obsidian Bible Reference is proudly powered by }) } - private setUpCollapsibleToggle(): void { - const setting = new Setting(this.containerEl) + private setUpCollapsibleOptions(): void { + new Setting(this.containerEl) .setName('Make Verses Collapsible *') - .setDesc( - 'Make the rendered verses collapsible, (This option will be disabled if Bible Icon Prefix option above is disabled)' - ) - setting.setTooltip( - "This will make the rendered verses collapsible, so that you can hide them when you don't need them" - ) - setting.addToggle((toggle) => { - if (!this.plugin.settings?.displayBibleIconPrefixAtHeader) { - toggle.setDisabled(true) - toggle.setTooltip('') - } - toggle - .setValue(!!this.plugin.settings?.collapsibleVerses) + .setDesc('Set how the rendered verses collapse, (This option will be disabled if Bible Icon Prefix option above is disabled)') + .setTooltip("'+' will make the callout be expanded on default. '-' will make the callout be collapsed by default. 'None' removes that options entirely") + .addDropdown((dropdown: DropdownComponent) => { + CollapsibleVersesCollection.forEach(({ name, description }) => { + dropdown.addOption(name, description) + }) + dropdown + .setValue( + this.plugin.settings.collapsibleVerses ?? CollapsibleVerses.Plus + ) .onChange(async (value) => { - this.plugin.settings.collapsibleVerses = value + this.plugin.settings.collapsibleVerses = value as CollapsibleVerses + console.debug('Bible Verse Collapsible To: ' + value) await this.plugin.saveSettings() + new Notice('Bible Verse Collapsible Settings Updated') EventStats.logSettingChange( 'changeVerseFormatting', - { key: `collapsible-${value}`, value: 1 }, + { key: `collapsible-verses-${value}`, value: 1 }, this.plugin.settings.optOutToEvents ) }) @@ -463,7 +466,7 @@ Obsidian Bible Reference is proudly powered by this.plugin.settings.displayBibleIconPrefixAtHeader = value await this.plugin.saveSettings() if (!value) { - this.plugin.settings.collapsibleVerses = false + this.plugin.settings.collapsibleVerses = CollapsibleVerses.None await this.plugin.saveSettings() } pluginEvent.trigger('bible-reference:settings:re-render', []) diff --git a/src/verse/BaseVerseFormatter.ts b/src/verse/BaseVerseFormatter.ts index 1b8d4e3..8c632c3 100644 --- a/src/verse/BaseVerseFormatter.ts +++ b/src/verse/BaseVerseFormatter.ts @@ -4,6 +4,7 @@ import { BibleVerseNumberFormat } from '../data/BibleVerseNumberFormat' import { VerseReference } from '../utils/splitBibleReference' import { BibleVerseFormat } from '../data/BibleVerseFormat' import { IVerse } from '../interfaces/IVerse' +import { CollapsibleVerses } from 'src/data/CollapsibleVerses' export abstract class BaseVerseFormatter { protected settings: BibleReferencePluginSettings @@ -78,8 +79,16 @@ export abstract class BaseVerseFormatter { if (this.settings.displayBibleIconPrefixAtHeader) { head += '[!bible]' - if (this.settings?.collapsibleVerses) { - head += '+' + switch (this.settings?.collapsibleVerses) { + case CollapsibleVerses.Plus: + head += '+' + break + case CollapsibleVerses.Minus: + head += '-' + break + case CollapsibleVerses.None: + head += '' + break } }