MCPcopy Index your code
hub / github.com/ZenNotes/zennotes / ParseTasks

Function ParseTasks

apps/server/internal/vault/parse.go:312–414  ·  view source on GitHub ↗

ParseTasks walks a markdown body and returns every checkbox task.

(path, title string, folder NoteFolder, body string)

Source from the content-addressed store, hash-verified

310
311// ParseTasks walks a markdown body and returns every checkbox task.
312func ParseTasks(path, title string, folder NoteFolder, body string) []Task {
313 normalized := strings.ReplaceAll(body, "\r\n", "\n")
314 defaults := parseNoteDefaults(normalized)
315 lines := strings.Split(normalized, "\n")
316
317 out := []Task{}
318 taskIndex := 0
319 inFence := false
320 fenceMarker := ""
321
322 fenceStart := regexp.MustCompile("^([ \t]*)(`{3,}|~{3,})")
323
324 for i, line := range lines {
325 if fm := fenceStart.FindStringSubmatch(line); fm != nil {
326 marker := fm[2]
327 if !inFence {
328 inFence = true
329 fenceMarker = marker
330 } else if marker == fenceMarker {
331 inFence = false
332 fenceMarker = ""
333 }
334 continue
335 }
336 if inFence {
337 continue
338 }
339 m := taskLineRe.FindStringSubmatch(line)
340 if m == nil {
341 continue
342 }
343 checkedChar := m[2]
344 tail := strings.TrimPrefix(m[3], "]")
345 checked := checkedChar == "x" || checkedChar == "X"
346
347 due := ""
348 priority := ""
349 waiting := false
350 tags := []string{}
351 stripped := tail
352
353 if dm := inlineDueRe.FindStringSubmatch(stripped); dm != nil {
354 if isValidIsoDate(dm[1]) {
355 due = dm[1]
356 }
357 stripped = inlineDueRe.ReplaceAllString(stripped, " ")
358 }
359 if pm := inlinePriority.FindStringSubmatch(stripped); pm != nil {
360 priority = normalizePriority(pm[1])
361 stripped = inlinePriority.ReplaceAllString(stripped, " ")
362 }
363 if inlineWaitingRe.MatchString(stripped) {
364 waiting = true
365 stripped = inlineWaitingRe.ReplaceAllString(stripped, " ")
366 }
367 for _, tm := range inlineTagRe.FindAllStringSubmatch(tail, -1) {
368 if len(tm) >= 2 {
369 tag := strings.ToLower(tm[1])

Callers 2

ScanTasksMethod · 0.85
ScanTasksForPathMethod · 0.85

Calls 5

appendFunction · 0.85
fmtTaskIDFunction · 0.85
parseNoteDefaultsFunction · 0.70
isValidIsoDateFunction · 0.70
normalizePriorityFunction · 0.70

Tested by

no test coverage detected