1import { renderToStaticMarkup } from "react-dom/server";
2import ReactMarkdown from "react-markdown";
3import remarkGfm from "remark-gfm";
4import { describe, expect, it } from "vite-plus/test";
5
6import { remarkNormalizeListItemIndentation } from "@t3tools/shared/markdownListIndentation";
7
8function renderMarkdown(markdown: string): string {
9 return renderToStaticMarkup(
10 <ReactMarkdown remarkPlugins={[remarkGfm, remarkNormalizeListItemIndentation]}>
11 {markdown}
12 </ReactMarkdown>,
13 );
14}
15
16describe("remarkNormalizeListItemIndentation", () => {
17 it("renders same-line over-indented list content as list text", () => {
18 const html = renderMarkdown(`why did you do this?
19
20- for (const step of rest.steps) {
21- if (step.request.body) {
22- step.request.body = "<redacted>";
23- }
24- }`);
25
26 expect(html).not.toContain("<pre>");
27 expect(html).toContain("<li>for (const step of rest.steps) {</li>");
28 expect(html).toContain("<li>if (step.request.body) {</li>");
29 expect(html).toContain("<li>step.request.body = "<redacted>";</li>");
30 });
31
32 it("preserves every recovered block separated by blank lines", () => {
33 const html = renderMarkdown(`- **first block**
34
35 [second block](https://example.com)`);
36
37 expect(html).toContain("<strong>first block</strong>");
38 expect(html).toContain('<a href="https://example.com">second block</a>');
39 });
40
41 it("recursively normalizes lists in recovered tail blocks", () => {
42 const html = renderMarkdown(`- first block
43
44 - nested block`);
45
46 expect(html).not.toContain("<pre>");
47 expect(html).toContain("<li>nested block</li>");
48 });
49
50 it("preserves fenced code blocks within list items", () => {
51 const html = renderMarkdown(`- \`\`\`ts
52 const value = 1;
53 \`\`\``);
54
55 expect(html).toContain('<pre><code class="language-ts">const value = 1;');
56 });
57
58 it("preserves indented code blocks that start below a list marker", () => {
59 const html = renderMarkdown(`-
60 const value = 1;`);
61
62 expect(html).toContain("<pre><code>const value = 1;");
63 });
64});