diff --git a/src/utils/VerseFormatter.ts b/src/utils/VerseFormatter.ts new file mode 100644 index 0000000..3a8de27 --- /dev/null +++ b/src/utils/VerseFormatter.ts @@ -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 "— ()" + * 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})`; +} diff --git a/test/VerseFormatter.test.ts b/test/VerseFormatter.test.ts new file mode 100644 index 0000000..2d900fa --- /dev/null +++ b/test/VerseFormatter.test.ts @@ -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)"); + }); +});