Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { markdownHtmlContent, markdownWithHtml, parseMarkdownDocument } from "./markdownDocument";
3import { markdownImageSources } from "./markdownImageSources";
4
5describe("HTML in native Markdown", () => {
6 it("preserves screenshot URLs and captions from GitHub HTML image embeds", () => {
7 expect(
8 markdownHtmlContent(
9 '<img width="900" alt="Before > after [settings]" src="https://example.com/before.png?a=1&b=2" />',
10 ),
11 ).toBe("![Before > after \\[settings\\]](<https://example.com/before.png?a=1\\&b=2>)");
12 expect(
13 markdownHtmlContent(
14 "<a href='https://example.com'><img src='https://example.com/banner.svg' alt='Review' /></a>",
15 ),
16 ).toBe("");
17 });
18
19 it("decodes HTML attributes once and preserves entity-shaped query values through Markdown", () => {
20 const markdown =
21 '<img alt="&lt;" src="https://example.com/shot.png?label=&lt;&sig=a%26b">';
22 expect(markdownWithHtml(markdown)).toBe(
23 "",
24 );
25 expect(markdownImageSources(markdown)).toEqual([
26 "https://example.com/shot.png?label=<&sig=a%26b",
27 ]);
28 const paragraph = parseMarkdownDocument(markdown).children[0];
29 expect(paragraph?.type).toBe("paragraph");
30 if (paragraph?.type === "paragraph")
31 expect(paragraph.children[0]).toMatchObject({ type: "image", alt: "<" });
32 });
33
34 it("ignores code delimiters in HTML attributes and comments when collecting screenshots", () => {
35 const markdown =
36 '<details data-example="`">\n<summary>Proof</summary>\n<img src="https://example.com/shot.png" alt="Screenshot">\n<!-- ` -->\n</details>';
37 expect(markdownHtmlContent(markdown)).toContain(
38 "",
39 );
40 expect(markdownImageSources(markdown)).toEqual(["https://example.com/shot.png"]);
41 expect(markdownWithHtml(markdown)).not.toContain("<img");
42 });
43
44 it("removes bot metadata and details wrappers while keeping the content", () => {
45 const markdown =
46 "<!-- generated bot metadata -->\n<details>\n<summary>Walkthrough</summary>\n\n## Changes\n\nText\n\n</details>";
47 const result = markdownWithHtml(markdown);
48 expect(result).not.toContain("<!--");
49 expect(result).not.toContain("<details>");
50 expect(result).toContain("**Walkthrough**");
51 expect(result).toContain("## Changes");
52 expect(parseMarkdownDocument(markdown).children.some((node) => node.type === "html")).toBe(
53 false,
54 );
55 });
56
57 it("collects HTML and Markdown screenshots while leaving inline and fenced code literal", () => {
58 const markdown =
59 '```html\n<img src="literal.png">\n```\n\nUse `<img src="inline.png">` here.\n\n<img src="one.png">\n\n\n\n<img src="one.png">';
60 expect(markdownImageSources(markdown)).toEqual(["one.png", "two.png"]);
61 const result = markdownWithHtml(markdown);
62 expect(result).toContain('```html\n<img src="literal.png">\n```');
63 expect(result).toContain('`<img src="inline.png">`');
64 });
65});