MCPcopy Create free account
hub / github.com/driangle/taskmd / ParseTaskContent

Function ParseTaskContent

sdk/go/parser/markdown.go:48–97  ·  view source on GitHub ↗

ParseTaskContent parses task content from bytes

(filePath string, content []byte)

Source from the content-addressed store, hash-verified

46
47// ParseTaskContent parses task content from bytes
48func ParseTaskContent(filePath string, content []byte) (*model.Task, error) {
49 if len(content) == 0 {
50 return nil, &ParseError{
51 FilePath: filePath,
52 Message: "file is empty",
53 }
54 }
55
56 frontmatter, body, err := extractFrontmatter(content)
57 if err != nil {
58 return nil, &ParseError{
59 FilePath: filePath,
60 Message: "failed to extract frontmatter",
61 Err: err,
62 }
63 }
64
65 task := &model.Task{
66 FilePath: filePath,
67 Body: body,
68 }
69
70 if len(frontmatter) > 0 {
71 if err := yaml.Unmarshal(frontmatter, task); err != nil {
72 return nil, &ParseError{
73 FilePath: filePath,
74 Message: "failed to parse YAML frontmatter",
75 Err: err,
76 }
77 }
78 // Backward compatibility: accept deprecated "created" field
79 if task.Created.IsZero() && !task.CreatedDeprecated.IsZero() {
80 task.Created = task.CreatedDeprecated
81 }
82 }
83
84 // Derive missing fields from filename
85 if task.ID == "" || task.Title == "" {
86 deriveFieldsFromFilename(task)
87 }
88
89 if !task.IsValid() {
90 return nil, &ParseError{
91 FilePath: filePath,
92 Message: "task is missing required fields (id or title)",
93 }
94 }
95
96 return task, nil
97}
98
99// deriveFieldsFromFilename extracts ID and title from a filename.
100// Supports these patterns:

Calls 3

IsValidMethod · 0.95
extractFrontmatterFunction · 0.85
deriveFieldsFromFilenameFunction · 0.85