6 + 7 - Added a bunch more settings for customizing the formatted passages and updated the README to reflect the changes made in issue 7.

This commit is contained in:
Caleb Campbell
2025-12-20 15:55:56 +11:00
parent aeaaaf55b8
commit b71a31792b
8 changed files with 202 additions and 31 deletions

View File

@@ -1,8 +1,9 @@
import LocalBibleRefPlugin from 'main';
import { App, normalizePath, Notice, PluginSettingTab, Setting, TextComponent } from 'obsidian';
import { PassageFormat } from './passage-reference';
import { PathSuggest } from './path-suggest';
import { VersionSuggest } from './version-suggest';
import PathSuggest from './path-suggest';
import { CalloutType, QuoteReferencePosition } from './settings';
import VersionSuggest from './version-suggest';
export default class LocalBibleRefSettingTab extends PluginSettingTab {
private plugin: LocalBibleRefPlugin;
@@ -17,7 +18,7 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
containerEl.empty();
new Setting(containerEl)
.setName('Configurations')
.setName('Required Settings')
.setHeading();
let biblesPathTimeout: number;
@@ -53,12 +54,12 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
});
new Setting(containerEl)
.setName('Defaults')
.setName('Optional Settings')
.setHeading();
let defaultVersionTimeout: number;
const defaultVersionSetting = new Setting(containerEl)
.setName('Default version shorthand')
.setName('Default version')
.setDesc('The version to use by default - shorthand. This should correspond to a folder in the bibles folder selected above.')
.addText(text => {
text.setPlaceholder('e.g. NIV')
@@ -113,7 +114,103 @@ export default class LocalBibleRefSettingTab extends PluginSettingTab {
this.plugin.settings.bibleFormat = value as BibleFormat;
await this.plugin.saveSettings();
}));
}
new Setting(containerEl)
.setName('Quote Format Settings')
.setDesc('Settings for the quote passage format.')
.setHeading();
new Setting(containerEl)
.setName('Include reference')
.setDesc('Whether to include a reference to the passage.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.quote.includeReference)
.onChange(async (value) => {
// toggle visibility of other paragraph reference settings
if (value) {
quoteRefPositionSetting.settingEl.removeClass('local-bible-ref-hidden');
quoteRefLinkSetting.settingEl.removeClass('local-bible-ref-hidden');
} else {
quoteRefPositionSetting.settingEl.addClass('local-bible-ref-hidden');
quoteRefLinkSetting.settingEl.addClass('local-bible-ref-hidden');
}
this.plugin.settings.quote.includeReference = value;
await this.plugin.saveSettings();
}));
const quoteRefPositionSetting = new Setting(containerEl)
.setName('Reference position')
.setDesc('Where to position the reference.')
.addDropdown(dropdown => dropdown
.addOptions({
beginning: 'Beginning',
end: 'End',
})
.setValue(this.plugin.settings.quote.referencePosition)
.onChange(async (value) => {
this.plugin.settings.quote.referencePosition = value as QuoteReferencePosition;
await this.plugin.saveSettings();
}));
const quoteRefLinkSetting = new Setting(containerEl)
.setName('Link to passage')
.setDesc('Whether the reference should link to the passage in the Bible.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.quote.linkToPassage)
.onChange(async (value) => {
this.plugin.settings.quote.linkToPassage = value;
await this.plugin.saveSettings();
}));
if (this.plugin.settings.quote.includeReference) {
quoteRefPositionSetting.settingEl.removeClass('local-bible-ref-hidden');
quoteRefLinkSetting.settingEl.removeClass('local-bible-ref-hidden');
} else {
quoteRefPositionSetting.settingEl.addClass('local-bible-ref-hidden');
quoteRefLinkSetting.settingEl.addClass('local-bible-ref-hidden');
}
new Setting(containerEl)
.setName('Callout Format Settings')
.setDesc('Settings for the callout passage format.')
.setHeading();
new Setting(containerEl)
.setName('Callout type')
.setDesc('The type of callout to use for passages.')
.addDropdown(dropdown => dropdown
.addOptions({
note: 'Note',
abstract: 'Abstract',
info: 'Info',
todo: 'Todo',
tip: 'Tip',
success: 'Success',
question: 'Question',
warning: 'Warning',
failure: 'Failure',
danger: 'Danger',
bug: 'Bug',
example: 'Example',
quote: 'Quote',
})
.setValue(this.plugin.settings.callout.type)
.onChange(async (value) => {
this.plugin.settings.callout.type = value as CalloutType;
await this.plugin.saveSettings();
}));
new Setting(containerEl)
.setName('Link to passage')
.setDesc('Whether the reference should link to the passage in the Bible.')
.addToggle(toggle => toggle
.setValue(this.plugin.settings.callout.linkToPassage)
.onChange(async (value) => {
this.plugin.settings.callout.linkToPassage = value;
await this.plugin.saveSettings();
}));
}
}
export enum BibleFormat {

View File

@@ -1,6 +1,6 @@
import { Book, BOOKS } from "./books";
export class PassageReference implements ChapterReference, PassageOptions {
export default class PassageReference implements ChapterReference, PassageOptions {
startChapter: number;
startVerse: number;
endChapter: number;

View File

@@ -10,11 +10,11 @@ import {
TFile,
TFolder,
} from "obsidian";
import { PassageFormat, PassageReference } from "./passage-reference";
import { LocalBibleRefSettings } from "./settings";
import { BibleFormat } from "./local-bible-ref-setting-tab";
import PassageReference, { PassageFormat } from "./passage-reference";
import LocalBibleRefSettings, { QuoteReferencePosition } from "./settings";
export class PassageSuggest extends EditorSuggest<PassageSuggestion> {
export default class PassageSuggest extends EditorSuggest<PassageSuggestion> {
private settings: LocalBibleRefSettings;
private noSettingsNotice: Notice;
@@ -295,13 +295,13 @@ export class PassageSuggest extends EditorSuggest<PassageSuggestion> {
return text.slice(0, 45) + "...";
}
/** Formats the final text for suggestion. */
private formatTexts(
texts: string[],
passageRef: PassageReference,
context: EditorSuggestContext
): string {
let formatted = "";
/** Formats the final text for suggestion. */
private formatTexts(
texts: string[],
passageRef: PassageReference,
context: EditorSuggestContext
): string {
let formatted = "";
switch (passageRef.format) {
case PassageFormat.Manuscript:
formatted = texts.join(" ").trim();
@@ -315,15 +315,37 @@ export class PassageSuggest extends EditorSuggest<PassageSuggestion> {
formatted = texts.join("\n\n").trim();
formatted += "\n\n";
break;
case PassageFormat.Quote:
case PassageFormat.Quote: {
const {
includeReference,
referencePosition,
linkToPassage
} = this.settings.quote;
let stringRef = '';
if (includeReference) {
if (linkToPassage) stringRef = this.generatePassageLink(passageRef, context);
else stringRef = passageRef.stringify();
if (referencePosition === QuoteReferencePosition.Beginning) stringRef += "\n";
else stringRef = `\n> ${stringRef}`;
}
formatted = "> ";
if (referencePosition === QuoteReferencePosition.Beginning) formatted += stringRef;
formatted += texts.join("\n\n").trim();
formatted = formatted.replace(/\n/gm, "\n> ");
if (referencePosition === QuoteReferencePosition.End) formatted += stringRef;
formatted += "\n\n";
break;
}
case PassageFormat.Callout: {
const passageLink = this.generatePassageLink(passageRef, context);
formatted = `> [!quote] ${passageLink}\n`;
const { type, linkToPassage } = this.settings.callout;
let stringRef = '';
if (linkToPassage) stringRef = this.generatePassageLink(passageRef, context);
else stringRef = passageRef.stringify();
formatted = `> [!${type}] ${stringRef}\n`;
formatted += texts.join("\n\n").trim();
formatted = formatted.replace(/\n/gm, "\n> ");
formatted += "\n\n";
@@ -331,8 +353,8 @@ export class PassageSuggest extends EditorSuggest<PassageSuggestion> {
}
}
return formatted;
}
return formatted;
}
/** Generates a link to the passage within the vault. */
private generatePassageLink(

View File

@@ -1,6 +1,6 @@
import { AbstractInputSuggest, App, TFolder } from "obsidian";
export class PathSuggest extends AbstractInputSuggest<string> {
export default class PathSuggest extends AbstractInputSuggest<string> {
private textInputEl: HTMLInputElement | HTMLDivElement;
constructor(app: App, textInputEl: HTMLInputElement | HTMLDivElement) {

View File

@@ -1,9 +1,39 @@
import { BibleFormat } from "./local-bible-ref-setting-tab";
import { PassageFormat } from "./passage-reference";
export interface LocalBibleRefSettings {
export default interface LocalBibleRefSettings {
biblesPath: string;
defaultVersionShorthand: string;
defaultPassageFormat: PassageFormat;
bibleFormat: BibleFormat;
quote: {
includeReference: boolean;
referencePosition: QuoteReferencePosition;
linkToPassage: boolean;
},
callout: {
type: CalloutType;
linkToPassage: boolean;
}
}
export enum QuoteReferencePosition {
Beginning = "beginning",
End = "end",
}
export enum CalloutType {
Note = "note",
Abstract = "abstract",
Info = "info",
Todo = "todo",
Tip = "tip",
Success = "success",
Question = "question",
Warning = "warning",
Failure = "failure",
Danger = "danger",
Bug = "bug",
Example = "example",
Quote = "quote",
}

View File

@@ -1,7 +1,7 @@
import { AbstractInputSuggest, App, TFolder } from "obsidian";
import { LocalBibleRefSettings } from "./settings";
import LocalBibleRefSettings from "./settings";
export class VersionSuggest extends AbstractInputSuggest<string> {
export default class VersionSuggest extends AbstractInputSuggest<string> {
private settings: LocalBibleRefSettings;
private textInputEl: HTMLInputElement | HTMLDivElement;