mirror of
https://github.com/scotttomaszewski/obsidian-disciples-journal.git
synced 2026-07-22 05:42:13 +00:00
feat: VerseFormatter for the three insert formats
This commit is contained in:
parent
edb18749da
commit
d0c3af1303
2 changed files with 44 additions and 0 deletions
21
src/utils/VerseFormatter.ts
Normal file
21
src/utils/VerseFormatter.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/** `` `Genesis 1:2-3, 5` `` — inline reference rendered by the plugin's hover preview. */
|
||||
export function formatInlineReference(label: string): string {
|
||||
return `\`${label}\``;
|
||||
}
|
||||
|
||||
/** A fenced ```bible block the plugin renders as the full passage. */
|
||||
export function formatCodeBlock(label: string): string {
|
||||
return "```bible\n" + label + "\n```";
|
||||
}
|
||||
|
||||
/**
|
||||
* A markdown blockquote of the actual verse text, ending in a "— <ref> (<version>)"
|
||||
* citation. Every line of `text` is prefixed so multi-line quotes stay inside the quote.
|
||||
*/
|
||||
export function formatBlockquote(label: string, text: string, version: string): string {
|
||||
const body = text
|
||||
.split("\n")
|
||||
.map((line) => `> ${line}`)
|
||||
.join("\n");
|
||||
return `${body}\n>\n> — ${label} (${version})`;
|
||||
}
|
||||
23
test/VerseFormatter.test.ts
Normal file
23
test/VerseFormatter.test.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { formatInlineReference, formatCodeBlock, formatBlockquote } from "../src/utils/VerseFormatter";
|
||||
|
||||
test("VerseFormatter", async (t) => {
|
||||
await t.test("inline reference is backtick-wrapped", () => {
|
||||
assert.equal(formatInlineReference("Genesis 1:2-3, 5"), "`Genesis 1:2-3, 5`");
|
||||
});
|
||||
|
||||
await t.test("code block is a fenced bible block", () => {
|
||||
assert.equal(formatCodeBlock("Genesis 1:2-3"), "```bible\nGenesis 1:2-3\n```");
|
||||
});
|
||||
|
||||
await t.test("blockquote quotes the text and cites the reference + version", () => {
|
||||
const out = formatBlockquote("John 3:16", "For God so loved the world...", "ESV");
|
||||
assert.equal(out, "> For God so loved the world...\n>\n> — John 3:16 (ESV)");
|
||||
});
|
||||
|
||||
await t.test("blockquote prefixes every wrapped line with '> '", () => {
|
||||
const out = formatBlockquote("Genesis 1:1", "line one\nline two", "ESV");
|
||||
assert.equal(out, "> line one\n> line two\n>\n> — Genesis 1:1 (ESV)");
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue