Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

markdownGithubAlerts.test.ts

46 lines1.7 KB

1import { toHtml } from "hast-util-to-html";
2import remarkGfm from "remark-gfm";
3import remarkParse from "remark-parse";
4import remarkRehype from "remark-rehype";
5import { type PluggableList, unified } from "unified";
6import { describe, expect, it } from "vite-plus/test";
7​
8import { remarkGithubAlerts } from "./markdownGithubAlerts.ts";
9​
10const processor = unified()
11 .use(remarkParse)
12 .use([remarkGfm, remarkGithubAlerts] satisfies PluggableList)
13 .use(remarkRehype, { allowDangerousHtml: true });
14​
15function renderMarkdown(markdown: string): string {
16 return toHtml(processor.runSync(processor.parse(markdown), markdown), {
17 allowDangerousHtml: true,
18 });
20​
21describe("remarkGithubAlerts", () => {
22 it("keeps content that follows a marker-only paragraph", () => {
23 const html = renderMarkdown("> [!WARNING]\n>\n> ### A heading\n>\n> And a paragraph.");
24​
25 expect(html).toContain('data-alert="warning"');
26 expect(html).not.toContain("[!WARNING]");
27 expect(html).toContain("A heading");
28 expect(html).toContain("And a paragraph.");
29 });
30​
31 it("tags a quote whose next line opens with an inline node rather than text", () => {
32 const html = renderMarkdown("> [!NOTE]\n> **Medium Risk** Changes live transcript routing.");
33​
34 expect(html).toContain('data-alert="note"');
35 expect(html).not.toContain("[!NOTE]");
36 expect(html).toContain("<strong>Medium Risk</strong>");
37 expect(html).toContain("Changes live transcript routing.");
38 });
39​
40 it("leaves a quote alone when the marker shares its line with anything else", () => {
41 const html = renderMarkdown("> [!NOTE] an ordinary quote");
42​
43 expect(html).not.toContain("data-alert");
44 expect(html).toContain("[!NOTE] an ordinary quote");
45 });
46});