import { describe, expect, it } from "vitest"; import { markdownToText, summarize } from "#lib/markup/text.ts"; describe("markdownToText", () => { it("keeps the label of a link", () => { expect( markdownToText("Fixes [#4656](https://tangled.org/tangled.org/core/issues/4656).") ).toBe("Fixes #4656."); }); it("drops markup around text", () => { expect(markdownToText("# Title\n\n**bold** and `code`\n\n- one\n- two")).toBe( "Title bold and code one two" ); }); it("keeps the alt text of an image and drops raw html", () => { expect(markdownToText("![a cat](cat.png)
done")).toBe("a cat done"); }); it("renders emoji shortcodes", () => { expect(markdownToText("ship it :rocket:")).toBe("ship it 🚀"); }); }); describe("summarize", () => { it("cuts long text with an ellipsis", () => { expect(summarize("word ".repeat(100), 20)).toBe("word word word word…"); }); it("keeps short text whole", () => { expect(summarize("short", 20)).toBe("short"); }); it("ends in an ellipsis when the body is cut before its end", () => { expect(summarize(`short\n\n${"filler ".repeat(1000)}`, 500)).toMatch(/…$/); }); it("reaches the text after a long html comment", () => { const body = `\n\nThe sidebar overlaps.`; expect(summarize(body)).toBe("The sidebar overlaps."); }); it("skips link definitions but keeps footnote-like text", () => { const defs = Array.from( { length: 80 }, (_, i) => `[r${i}]: https://example.com/${"p/".repeat(30)}` ); expect(summarize(`${defs.join("\n")}\n\nSee [r1] and [^1]: stays.`)).toBe( "See [r1] and [^1]: stays." ); }); it("leaves an unclosed comment as it is and stays linear on many of them", () => { expect(summarize("a