Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last <br/> tag, add toggle command for Bible Icon Prefix setting, and add collapsible option for callout options #251

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/data/CollapsibleVerses.ts
Original file line number Diff line number Diff line change
@@ -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',
},
]
7 changes: 4 additions & 3 deletions src/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -61,7 +62,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...'
14 changes: 14 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -154,6 +157,17 @@ export default class BibleReferencePlugin extends Plugin {
})
}

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
Expand Down
41 changes: 22 additions & 19 deletions src/ui/BibleReferenceSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
)
})
Expand All @@ -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', [])
Expand Down
31 changes: 21 additions & 10 deletions src/verse/BaseVerseFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,17 +54,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('<br/>') // Remove the last <br/> 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)
Expand All @@ -76,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
}
}

Expand Down
Loading