mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
148 lines
3.5 KiB
TypeScript
148 lines
3.5 KiB
TypeScript
import { parser, serializer } from ".";
|
|
|
|
it("renders an empty doc", () => {
|
|
const ast = parser.parse("");
|
|
|
|
expect(ast?.toJSON()).toEqual({
|
|
content: [{ type: "paragraph" }],
|
|
type: "doc",
|
|
});
|
|
});
|
|
|
|
it("parses lowercase alpha lists", () => {
|
|
const ast = parser.parse("a. First item\nb. Second item");
|
|
|
|
expect(ast?.toJSON()).toEqual({
|
|
content: [
|
|
{
|
|
attrs: { listStyle: "lower-alpha", order: 1 },
|
|
content: [
|
|
{
|
|
content: [
|
|
{
|
|
content: [{ text: "First item", type: "text" }],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
type: "list_item",
|
|
},
|
|
{
|
|
content: [
|
|
{
|
|
content: [{ text: "Second item", type: "text" }],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
type: "list_item",
|
|
},
|
|
],
|
|
type: "ordered_list",
|
|
},
|
|
],
|
|
type: "doc",
|
|
});
|
|
});
|
|
|
|
it("parses uppercase alpha lists", () => {
|
|
const ast = parser.parse("A. First item\nB. Second item");
|
|
|
|
expect(ast?.toJSON()).toEqual({
|
|
content: [
|
|
{
|
|
attrs: { listStyle: "upper-alpha", order: 1 },
|
|
content: [
|
|
{
|
|
content: [
|
|
{
|
|
content: [{ text: "First item", type: "text" }],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
type: "list_item",
|
|
},
|
|
{
|
|
content: [
|
|
{
|
|
content: [{ text: "Second item", type: "text" }],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
type: "list_item",
|
|
},
|
|
],
|
|
type: "ordered_list",
|
|
},
|
|
],
|
|
type: "doc",
|
|
});
|
|
});
|
|
|
|
it("parses alpha lists with blank lines (issue example)", () => {
|
|
const markdown = `## 3. Step Three
|
|
|
|
a. Do this.
|
|
|
|
b. Do that.`;
|
|
|
|
const ast = parser.parse(markdown);
|
|
const json = ast?.toJSON();
|
|
|
|
// Find the ordered_list in the result
|
|
const orderedList = json?.content?.find(
|
|
(node: { type: string }) => node.type === "ordered_list"
|
|
);
|
|
|
|
expect(orderedList).toBeDefined();
|
|
expect(orderedList?.attrs.listStyle).toBe("lower-alpha");
|
|
expect(orderedList?.attrs.order).toBe(1);
|
|
expect(orderedList?.content).toHaveLength(2);
|
|
});
|
|
|
|
it("preserves numeric lists", () => {
|
|
const ast = parser.parse("1. First item\n2. Second item");
|
|
|
|
expect(ast?.toJSON()).toEqual({
|
|
content: [
|
|
{
|
|
attrs: { listStyle: "number", order: 1 },
|
|
content: [
|
|
{
|
|
content: [
|
|
{
|
|
content: [{ text: "First item", type: "text" }],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
type: "list_item",
|
|
},
|
|
{
|
|
content: [
|
|
{
|
|
content: [{ text: "Second item", type: "text" }],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
type: "list_item",
|
|
},
|
|
],
|
|
type: "ordered_list",
|
|
},
|
|
],
|
|
type: "doc",
|
|
});
|
|
});
|
|
|
|
it("serializes lowercase alpha lists back to markdown", () => {
|
|
const ast = parser.parse("a. First item\nb. Second item");
|
|
const output = serializer.serialize(ast);
|
|
|
|
expect(output.trim()).toBe("a. First item\nb. Second item");
|
|
});
|
|
|
|
it("serializes uppercase alpha lists back to markdown", () => {
|
|
const ast = parser.parse("A. First item\nB. Second item");
|
|
const output = serializer.serialize(ast);
|
|
|
|
expect(output.trim()).toBe("A. First item\nB. Second item");
|
|
});
|