MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / parseTasksFromBody

Function parseTasksFromBody

packages/shared-domain/src/tasks.ts:211–267  ·  view source on GitHub ↗
(body: string, ctx: ParseTasksContext)

Source from the content-addressed store, hash-verified

209 * byte-for-byte identical to `toggleTaskAtIndex` so round-trip edits stay
210 * stable. */
211export function parseTasksFromBody(body: string, ctx: ParseTasksContext): VaultTask[] {
212 const normalized = body.replace(/\r\n/g, '\n')
213 const { defaults } = parseNoteDefaults(normalized)
214 const lines = normalized.split('\n')
215 const tasks: VaultTask[] = []
216
217 let taskIndex = 0
218 let inFence = false
219 let fenceMarker: string | null = null
220
221 for (let i = 0; i < lines.length; i++) {
222 const line = lines[i]
223
224 const fenceMatch = line.match(FENCE_RE)
225 if (fenceMatch) {
226 const marker = fenceMatch[2]
227 if (!inFence) {
228 inFence = true
229 fenceMarker = marker
230 } else if (marker === fenceMarker) {
231 inFence = false
232 fenceMarker = null
233 }
234 continue
235 }
236 if (inFence) continue
237
238 const taskMatch = line.match(TASK_LINE_RE)
239 if (!taskMatch) continue
240
241 const checkedChar = taskMatch[2]
242 const tail = taskMatch[3].replace(/^\]/, '') // drop the closing `]` of the checkbox
243 const checked = checkedChar === 'x' || checkedChar === 'X'
244
245 const tokens = extractTokens(tail)
246
247 tasks.push({
248 id: `${ctx.path}#${taskIndex}`,
249 sourcePath: ctx.path,
250 noteTitle: ctx.title,
251 noteFolder: ctx.folder,
252 lineNumber: i,
253 taskIndex,
254 rawText: line,
255 content: tokens.stripped || tail.trim(),
256 checked,
257 due: tokens.due ?? defaults.due,
258 priority: tokens.priority ?? defaults.priority,
259 waiting: tokens.waiting,
260 tags: tokens.tags
261 })
262
263 taskIndex += 1
264 }
265
266 return tasks
267}
268

Callers 2

store.tsFile · 0.90
CalendarPanelFunction · 0.90

Calls 2

parseNoteDefaultsFunction · 0.70
extractTokensFunction · 0.70

Tested by

no test coverage detected