fix: Checklist conversion corrupts neighbouring lists (#13724)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-09-11 18:44:21 -04:00
1 parent 35dd15b971
commit ab40dda966
2 files changed
+48 -2

No files matched your search

+42
View File
@@ -94,3 +94,45 @@ it("converts an ordered list containing a checkbox item", () => {
expect(checkboxList?.content?.[0].type).toBe("checkbox_item");
expect(checkboxList?.content?.[1].type).toBe("checkbox_item");
});
it("leaves neighbouring lists untouched when a checklist has multiple items", () => {
const markdown = `## Before 1
- B1 a
- B1 b
## Before 2
- B2 a
- B2 b
## Tasks
- [ ] task one
- [ ] task two
## After 1
- A1 a
- A1 b
## After 2
- A2 a`;
const ast = parser.parse(markdown);
const json = ast?.toJSON();
const checkboxLists = findNodes(json, "checkbox_list");
expect(checkboxLists).toHaveLength(1);
expect(checkboxLists[0]?.content).toHaveLength(2);
const bulletLists = findNodes(json, "bullet_list");
expect(bulletLists).toHaveLength(4);
for (const list of bulletLists) {
for (const item of list?.content ?? []) {
expect(item.type).toBe("list_item");
}
}
const output = serializer.serialize(ast);
expect(output).toContain("B2 a");
expect(output).toContain("A1 a");
expect(output).toContain("A1 b");
expect(output).not.toContain("[ ] B2 a");
});
+6 -2
View File
@@ -24,13 +24,17 @@ function isListItem(token: Token): boolean {
function isListOpen(token: Token): boolean {
return (
token.type === "bullet_list_open" || token.type === "ordered_list_open"
token.type === "bullet_list_open" ||
token.type === "ordered_list_open" ||
token.type === "checkbox_list_open"
);
}
function isListClose(token: Token): boolean {
return (
token.type === "bullet_list_close" || token.type === "ordered_list_close"
token.type === "bullet_list_close" ||
token.type === "ordered_list_close" ||
token.type === "checkbox_list_close"
);
}