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

Allow non-verse headings in between verses #8

Merged
merged 4 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Requires you to have bible in markdown in your vault, with similar structure to
- *exception*: if your file is named "Gen-01", you can type either "Gen-01,1-4" or "Gen 1,1-4"

## Wrong verses are linked? Or linking doesn't work and you have files with right format?
- Go to Plugin settings and try changing "Verse offset" accordingly.
- Go to Plugin settings and try changing "Verse offset" or "Verse heading level" accordingly.

## Installing
Available through Obsidian Community plugins (Settings/Comumnity plugins)
Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface PluginSettings {
prefix: string;
linkEndVerse: boolean;
verseOffset: number;
verseHeadingLevel?: number;
useInvisibleLinks: boolean;
newLines: boolean;
eachVersePrefix: string;
Expand All @@ -24,6 +25,7 @@ const DEFAULT_SETTINGS: Partial<PluginSettings> = {
prefix: "",
linkEndVerse: false,
verseOffset: 0,
verseHeadingLevel: undefined,
useInvisibleLinks: true,
newLines: false,
eachVersePrefix: "",
Expand Down
20 changes: 19 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ export class SettingsTab extends PluginSettingTab {
})
)

new Setting(containerEl)
.setName("Verse heading level")
.setDesc('If set, only headings of specified level are considered verses (if first heading of this level is always a verse, also set "Verse offset" to -1)')
.addDropdown((dropdown) => {
dropdown.addOption("any", "any")
dropdown.addOption("6", "######")
dropdown.addOption("5", "#####")
dropdown.addOption("4", "####")
dropdown.addOption("3", "###")
dropdown.addOption("2", "##")
dropdown.addOption("1", "#")
dropdown.setValue(this.plugin.settings.verseHeadingLevel?.toString() ?? "any")
dropdown.onChange(async (value) => {
this.plugin.settings.verseHeadingLevel = value === "any" ? undefined : Number(value);
await this.plugin.saveSettings();
})
})

new Setting(containerEl)
.setName("Link prefix")
.setDesc("String inserted in front of linked verses, for example '>' for quote. Leave empty for no prefix.")
Expand Down Expand Up @@ -156,7 +174,7 @@ export class SettingsTab extends PluginSettingTab {
dropdown.setValue(this.plugin.settings.linkTypePreset)
dropdown.onChange(async (value) => {
this.plugin.settings.linkTypePreset = value as LinkType;
await this.plugin.saveSettings;
await this.plugin.saveSettings();
})
})

Expand Down
5 changes: 3 additions & 2 deletions src/utils/convert-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function getVerseText(verseNumber: number, headings: HeadingCache[], lines: stri
new Notice("Logical error - please create issue on plugin's GitHub with your input and the file you were referencing. Thank you!")
throw `HeadingLine ${headingLine + 1} is out of range of lines with length ${lines}`
}
return lines[headingLine + 1]
return lines[headingLine + 1] || lines[headingLine + 2]
}

/**
Expand All @@ -156,7 +156,8 @@ function tryConvertToOBSKFileName(bookAndChapter: string) {
async function createCopyOutput(app: App, tFile: TFile, userChapterInput: string, fileName: string, beginVerse: number, endVerse: number, settings: PluginSettings) {
const file = app.vault.read(tFile)
const lines = (await file).split(/\r?\n/)
const headings = app.metadataCache.getFileCache(tFile).headings;
const verseHeadingLevel = settings.verseHeadingLevel
const headings = app.metadataCache.getFileCache(tFile).headings.filter(heading => !verseHeadingLevel || heading.level === verseHeadingLevel)
const beginVerseNoOffset = beginVerse
const endVerseNoOffset = endVerse
beginVerse += settings.verseOffset
Expand Down