This commit is contained in:
roomote-v0[bot] 2026-04-07 00:34:17 +00:00 committed by GitHub
commit 0e9612ff10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View file

@ -177,7 +177,10 @@ function normalizeStatus(status: string | undefined): TodoStatus {
export function parseMarkdownChecklist(md: string): TodoItem[] {
if (typeof md !== "string") return []
const lines = md
// Normalize literal escape sequences (e.g. "\\n", "\\r\\n") that some
// models/providers send instead of actual newline characters.
const normalized = md.replace(/\\r\\n|\\n/g, "\n")
const lines = normalized
.split(/\r?\n/)
.map((l) => l.trim())
.filter(Boolean)

View file

@ -205,6 +205,35 @@ Just some text
})
})
describe("literal escape sequence normalization", () => {
it("should parse items separated by literal \\n escape sequences", () => {
const md = "[ ] Task 1\\n[x] Task 2\\n[-] Task 3"
const result = parseMarkdownChecklist(md)
expect(result).toHaveLength(3)
expect(result[0].content).toBe("Task 1")
expect(result[0].status).toBe("pending")
expect(result[1].content).toBe("Task 2")
expect(result[1].status).toBe("completed")
expect(result[2].content).toBe("Task 3")
expect(result[2].status).toBe("in_progress")
})
it("should parse items separated by literal \\r\\n escape sequences", () => {
const md = "[ ] Task 1\\r\\n- [x] Task 2\\r\\n[~] Task 3"
const result = parseMarkdownChecklist(md)
expect(result).toHaveLength(3)
expect(result[0].content).toBe("Task 1")
expect(result[1].content).toBe("Task 2")
expect(result[2].content).toBe("Task 3")
})
it("should handle a mix of literal and actual newlines", () => {
const md = "[ ] Task 1\\n[x] Task 2\n[-] Task 3"
const result = parseMarkdownChecklist(md)
expect(result).toHaveLength(3)
})
})
describe("ID generation", () => {
it("should generate consistent IDs for the same content and status", () => {
const md1 = `[ ] Task 1