Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import { 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(" <br> 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 = `<!-- ${"template instructions ".repeat(300)} -->\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 <!-- b")).toBe("a <!-- b"); const started = performance.now(); summarize("<!--".repeat(60_000)); expect(performance.now() - started).toBeLessThan(500); });});