mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* Initial plan * Add alpha list markdown parsing support Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Add integration tests for alpha list parsing and serialization Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Address code review feedback - improve marker matching logic Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> * Add explanatory comment for line offset constant Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tommoor <380914+tommoor@users.noreply.github.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import markdownit from "markdown-it";
|
|
import alphaListsRule from "../rules/alphaLists";
|
|
|
|
describe("Alpha Lists Plugin", () => {
|
|
it("should parse lowercase alphabetic lists", () => {
|
|
const md = markdownit().use(alphaListsRule);
|
|
const result = md.parse("a. First item\nb. Second item", {});
|
|
|
|
// Find ordered_list_open token
|
|
const listToken = result.find((t) => t.type === "ordered_list_open");
|
|
expect(listToken).toBeDefined();
|
|
expect(listToken?.attrGet("data-list-style")).toBe("lower-alpha");
|
|
});
|
|
|
|
it("should parse uppercase alphabetic lists", () => {
|
|
const md = markdownit().use(alphaListsRule);
|
|
const result = md.parse("A. First item\nB. Second item", {});
|
|
|
|
// Find ordered_list_open token
|
|
const listToken = result.find((t) => t.type === "ordered_list_open");
|
|
expect(listToken).toBeDefined();
|
|
expect(listToken?.attrGet("data-list-style")).toBe("upper-alpha");
|
|
});
|
|
|
|
it("should preserve numeric lists", () => {
|
|
const md = markdownit().use(alphaListsRule);
|
|
const result = md.parse("1. First item\n2. Second item", {});
|
|
|
|
// Find ordered_list_open token
|
|
const listToken = result.find((t) => t.type === "ordered_list_open");
|
|
expect(listToken).toBeDefined();
|
|
expect(listToken?.attrGet("data-list-style")).toBeNull();
|
|
});
|
|
|
|
it("should handle the issue example", () => {
|
|
const md = markdownit().use(alphaListsRule);
|
|
const text = `## 3. Step Three
|
|
|
|
a. Do this.
|
|
|
|
b. Do that.`;
|
|
|
|
const result = md.parse(text, {});
|
|
|
|
// Check that we have an ordered list
|
|
const listToken = result.find((t) => t.type === "ordered_list_open");
|
|
expect(listToken).toBeDefined();
|
|
expect(listToken?.attrGet("data-list-style")).toBe("lower-alpha");
|
|
|
|
// Check that we have two list items
|
|
const listItems = result.filter((t) => t.type === "list_item_open");
|
|
expect(listItems.length).toBe(2);
|
|
});
|
|
|
|
it("should handle multiple separate alpha lists", () => {
|
|
const md = markdownit().use(alphaListsRule);
|
|
const text = `a. First list item
|
|
|
|
b. Second list item
|
|
|
|
Some text in between
|
|
|
|
A. Upper list item
|
|
|
|
B. Upper list item 2`;
|
|
|
|
const result = md.parse(text, {});
|
|
|
|
// Check that we have two ordered lists
|
|
const listTokens = result.filter((t) => t.type === "ordered_list_open");
|
|
expect(listTokens.length).toBe(2);
|
|
expect(listTokens[0]?.attrGet("data-list-style")).toBe("lower-alpha");
|
|
expect(listTokens[1]?.attrGet("data-list-style")).toBe("upper-alpha");
|
|
});
|
|
});
|