(md: string)
| 176 | } |
| 177 | |
| 178 | export function parseMarkdownChecklist(md: string): TodoItem[] { |
| 179 | if (typeof md !== "string") return [] |
| 180 | const lines = md |
| 181 | .split(/\r?\n/) |
| 182 | .map((l) => l.trim()) |
| 183 | .filter(Boolean) |
| 184 | const todos: TodoItem[] = [] |
| 185 | for (const line of lines) { |
| 186 | const match = line.match(/^(?:-\s*)?\[\s*([ xX\-~])\s*\]\s+(.+)$/) |
| 187 | if (!match) continue |
| 188 | let status: TodoStatus = "pending" |
| 189 | if (match[1] === "x" || match[1] === "X") status = "completed" |
| 190 | else if (match[1] === "-" || match[1] === "~") status = "in_progress" |
| 191 | const id = crypto |
| 192 | .createHash("md5") |
| 193 | .update(match[2] + status) |
| 194 | .digest("hex") |
| 195 | todos.push({ |
| 196 | id, |
| 197 | content: match[2], |
| 198 | status, |
| 199 | }) |
| 200 | } |
| 201 | return todos |
| 202 | } |
| 203 | |
| 204 | export function setPendingTodoList(todos: TodoItem[]) { |
| 205 | approvedTodoList = todos |
no test coverage detected