@blocknote/core
Version:
A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.
177 lines (166 loc) • 3.62 kB
text/typescript
import { describe, expect, it } from "vitest";
import { nestedListsToBlockNoteStructure } from "./nestedLists.js";
import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeFormat from "rehype-format";
import rehypeStringify from "rehype-stringify";
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 = `<ul>
<li>
Bullet List Item 1
<ul>
<li>
Nested Bullet List Item 1
</li>
<li>
Nested Bullet List Item 2
</li>
</ul>
</li>
<li>
Bullet List Item 2
</li>
</ul>`;
await testHTML(html);
});
it("Lifts nested bullet lists without li", async () => {
const html = `<ul>
Bullet List Item 1
<ul>
<li>
Nested Bullet List Item 1
</li>
<li>
Nested Bullet List Item 2
</li>
</ul>
<li>
Bullet List Item 2
</li>
</ul>`;
await testHTML(html);
});
it("Lifts nested bullet lists with content after nested list", async () => {
const html = `<ul>
<li>
Bullet List Item 1
<ul>
<li>
Nested Bullet List Item 1
</li>
<li>
Nested Bullet List Item 2
</li>
</ul>
More content in list item 1
</li>
<li>
Bullet List Item 2
</li>
</ul>`;
await testHTML(html);
});
it("Lifts multiple bullet lists", async () => {
const html = `<ul>
<li>
Bullet List Item 1
<ul>
<li>
Nested Bullet List Item 1
</li>
<li>
Nested Bullet List Item 2
</li>
</ul>
<ul>
<li>
Nested Bullet List Item 3
</li>
<li>
Nested Bullet List Item 4
</li>
</ul>
</li>
<li>
Bullet List Item 2
</li>
</ul>`;
await testHTML(html);
});
it("Lifts multiple bullet lists with content in between", async () => {
const html = `<ul>
<li>
Bullet List Item 1
<ul>
<li>
Nested Bullet List Item 1
</li>
<li>
Nested Bullet List Item 2
</li>
</ul>
In between content
<ul>
<li>
Nested Bullet List Item 3
</li>
<li>
Nested Bullet List Item 4
</li>
</ul>
</li>
<li>
Bullet List Item 2
</li>
</ul>`;
await testHTML(html);
});
it("Lifts nested numbered lists", async () => {
const html = `<ol>
<li>
Numbered List Item 1
<ol>
<li>
Nested Numbered List Item 1
</li>
<li>
Nested Numbered List Item 2
</li>
</ol>
</li>
<li>
Numbered List Item 2
</li>
</ol>`;
await testHTML(html);
});
it("Lifts nested mixed lists", async () => {
const html = `<ol>
<li>
Numbered List Item 1
<ul>
<li>
Bullet List Item 1
</li>
<li>
Bullet List Item 2
</li>
</ul>
</li>
<li>
Numbered List Item 2
</li>
</ol>`;
await testHTML(html);
});
});