Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { parseInlineMarkdown } from "./composer-rich-text";
4
5describe("composer rich text markdown", () => {
6 it("parses bold markers into styled spans", () => {
7 expect(parseInlineMarkdown("hello **bold** world")).toEqual([
8 { text: "hello ", marks: [] },
9 { text: "bold", marks: ["bold"] },
10 { text: " world", marks: [] },
11 ]);
12 });
13
14 it("preserves unmatched markers, escaped markers, and identifiers", () => {
15 for (const text of [
16 "plain text",
17 "snake_case",
18 "unmatched **",
19 "** spaced **",
20 "\\*literal\\*",
21 ]) {
22 expect(parseInlineMarkdown(text)).toEqual([{ text, marks: [] }]);
23 }
24 });
25
26 it("renders triple markers and nested styles", () => {
27 expect(parseInlineMarkdown("***both***")).toEqual([
28 { text: "both", marks: ["bold", "italic"] },
29 ]);
30 expect(parseInlineMarkdown("*a **b** c*")).toEqual([
31 { text: "a ", marks: ["italic"] },
32 { text: "b", marks: ["italic", "bold"] },
33 { text: " c", marks: ["italic"] },
34 ]);
35 expect(parseInlineMarkdown("**a `code` c**")).toEqual([
36 { text: "a ", marks: ["bold"] },
37 { text: "code", marks: ["bold", "code"] },
38 { text: " c", marks: ["bold"] },
39 ]);
40 });
41
42 it("preserves crossing italic and bold spans", () => {
43 expect(parseInlineMarkdown("*a**b*****c**")).toEqual([
44 { text: "a", marks: ["italic"] },
45 { text: "b", marks: ["italic", "bold"] },
46 { text: "c", marks: ["bold"] },
47 ]);
48 });
49
50 it("keeps repeated and alternate delimiters literal inside an active mark", () => {
51 const repeated = "*".repeat(10_000);
52 expect(parseInlineMarkdown(repeated + "text" + repeated)).toEqual([
53 { text: repeated.slice(2) + "text", marks: ["bold"] },
54 { text: repeated.slice(2), marks: [] },
55 ]);
56 const alternate = "__".repeat(5_000);
57 expect(parseInlineMarkdown("**~~" + alternate + "text" + alternate + "~~**")).toEqual([
58 { text: alternate + "text" + alternate, marks: ["bold", "strike"] },
59 ]);
60 });
61
62 it("keeps code span contents literal", () => {
63 expect(parseInlineMarkdown("`**not bold**`")).toEqual([
64 { text: "**not bold**", marks: ["code"] },
65 ]);
66 });
67});