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

@@ -10,7 +10,11 @@ This plugin takes heavy inspiration from the [Bible Reference](https://github.co
### Getting Started
To start with, you will need to format a Bible for your own vault. Some instructions on this can be found [below](#bible-markdown-format) (this plugin uses a different markdown format to *Bible Linker*). I've also already formatted the Public Domain World English Bible so you can [download](https://github.com/camelChief/markdown-webp) that and just get started. Once you've done that, open up the *Local Bible Ref* settings and fill in at least the *Bibles path* field. Then, to use the plugin, simply open a new note and use the `--` reference prefix to grab a passage of scripture. There are also additional options (similar to terminal command options) you can provide to the reference to indicate which version to use and what markdown format to display the passage in. More information can be found [below](#usage).
To start with, you will need to format a Bible for your own vault.
If you would like to use your vault Bible for reading, I would encourage you to format it in the original *Local Bible Ref* format. Some instructions on this can be found [below](#bible-markdown-format). I've also already formatted the Public Domain World English Bible so you can [download](https://github.com/camelChief/markdown-webp) that and just get started. If you don't want to go to all that hassle, you can use your existing *Bible Linker* Bible with this plugin! In order to do that, simply select "Bible Linker" as your Bible format in the *Local Bible Ref* settings.
Once you've done that, open up the *Local Bible Ref* settings and fill in at least the *Bibles path* field. Then, to use the plugin, simply open a new note and use the `--` reference prefix to grab a passage of scripture. There are also additional options (similar to terminal command options) you can provide to the reference to indicate which version to use and what markdown format to display the passage in. More information can be found [below](#usage).
![localBibleRef1](https://github.com/user-attachments/assets/b8b5440b-8f47-4462-987e-a52791d758be)
@@ -34,7 +38,7 @@ The referencing syntax also allows for a lot of flexibility:
### Options
Local Bible Ref also allows you to provide a few options to a reference to specify which version you would like to use as well as what markdown format to use. Add an option to a reference by adding a `+` followed by the option (in any order): `--gen1:1-5+esv`
*Local Bible Ref* also allows you to provide a few options to a reference to specify which version you would like to use as well as what markdown format to use. Add an option to a reference by adding a `+` followed by the option (in any order): `--gen1:1-5+esv`
You can also pass multiple options by simply chaining them: `-- John 1:1 +quote +esv`
@@ -73,5 +77,4 @@ If all of this seems a bit confusing, please check out the aforementioned [markd
## Limitations
- Bible referencing **does not work** with the *Bible Linker* style of markdown Bible.
- Referencing does not yet support multiple passages: `Genesis 1:1; John 1:1`

23
main.ts
View File

@@ -1,8 +1,8 @@
import { Plugin } from 'obsidian';
import LocalBibleRefSettingTab, { BibleFormat } from 'src/local-bible-ref-setting-tab';
import { PassageFormat } from 'src/passage-reference';
import { PassageSuggest } from 'src/passage-suggest';
import { LocalBibleRefSettings } from 'src/settings';
import PassageSuggest from 'src/passage-suggest';
import LocalBibleRefSettings, { CalloutType, QuoteReferencePosition } from 'src/settings';
export default class LocalBibleRefPlugin extends Plugin {
settings: LocalBibleRefSettings;
@@ -17,12 +17,31 @@ export default class LocalBibleRefPlugin extends Plugin {
async loadSettings() {
this.settings = await this.loadData();
const quoteSettings = {
includeReference: true,
referencePosition: QuoteReferencePosition.End,
linkToPassage: true,
};
const calloutSettings = {
type: CalloutType.Quote,
linkToPassage: true,
};
this.settings ??= {
biblesPath: '',
defaultVersionShorthand: '',
defaultPassageFormat: PassageFormat.Callout,
bibleFormat: BibleFormat.LocalBibleRef,
quote: quoteSettings,
callout: calloutSettings,
};
if (!this.settings.quote) this.settings.quote = quoteSettings;
if (!this.settings.callout) this.settings.callout = calloutSettings;
await this.saveSettings();
}
async saveSettings() {

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;