import rehypeFormat from "rehype-format";
import rehypeParse from "rehype-parse";
import rehypeStringify from "rehype-stringify";
import { unified } from "unified";
import { describe, expect, it } from "vitest";
import { nestedListsToBlockNoteStructure } from "./nestedLists";
async function testHTML(html: string) {
const htmlNode = nestedListsToBlockNoteStructure(html);
const pretty = await unified()
.use(rehypeParse, { fragment: true })
.use(rehypeFormat)
.use(rehypeStringify)
.process(htmlNode.innerHTML);
expect(pretty.value).toMatchSnapshot();
}
describe("Lift nested lists", () => {
it("Lifts nested bullet lists", async () => {
const html = `
-
Bullet List Item 1
-
Nested Bullet List Item 1
-
Nested Bullet List Item 2
-
Bullet List Item 2
`;
await testHTML(html);
});
it("Lifts nested bullet lists without li", async () => {
const html = `
Bullet List Item 1
-
Nested Bullet List Item 1
-
Nested Bullet List Item 2
-
Bullet List Item 2
`;
await testHTML(html);
});
it("Lifts nested bullet lists with content after nested list", async () => {
const html = `
-
Bullet List Item 1
-
Nested Bullet List Item 1
-
Nested Bullet List Item 2
More content in list item 1
-
Bullet List Item 2
`;
await testHTML(html);
});
it("Lifts multiple bullet lists", async () => {
const html = `
-
Bullet List Item 1
-
Nested Bullet List Item 1
-
Nested Bullet List Item 2
-
Nested Bullet List Item 3
-
Nested Bullet List Item 4
-
Bullet List Item 2
`;
await testHTML(html);
});
it("Lifts multiple bullet lists with content in between", async () => {
const html = `
-
Bullet List Item 1
-
Nested Bullet List Item 1
-
Nested Bullet List Item 2
In between content
-
Nested Bullet List Item 3
-
Nested Bullet List Item 4
-
Bullet List Item 2
`;
await testHTML(html);
});
it("Lifts nested numbered lists", async () => {
const html = `
-
Numbered List Item 1
-
Nested Numbered List Item 1
-
Nested Numbered List Item 2
-
Numbered List Item 2
`;
await testHTML(html);
});
it("Lifts nested mixed lists", async () => {
const html = `
-
Numbered List Item 1
-
Bullet List Item 1
-
Bullet List Item 2
-
Numbered List Item 2
`;
await testHTML(html);
});
});