feat: 任务解析器及测试
This commit is contained in:
16
src/core/task-parser.ts
Normal file
16
src/core/task-parser.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { TaskItem } from "../types.ts";
|
||||
|
||||
export function parseTasks(content: string): TaskItem[] {
|
||||
const tasks: TaskItem[] = [];
|
||||
const lines = content.split("\n");
|
||||
for (const line of lines) {
|
||||
const match = line.match(/^[\s]*- \[([ xX])\] (.*)$/);
|
||||
if (match) {
|
||||
tasks.push({
|
||||
checked: match[1] !== " ",
|
||||
text: match[2],
|
||||
});
|
||||
}
|
||||
}
|
||||
return tasks;
|
||||
}
|
||||
Reference in New Issue
Block a user