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

Function setTaskPriorityAtIndex

packages/shared-domain/src/tasklists.ts:171–194  ·  view source on GitHub ↗
(
  markdown: string,
  taskIndex: number,
  priority: TaskPriority | null
)

Source from the content-addressed store, hash-verified

169/** Replace, insert, or remove the priority token (`!high|!med|!low`)
170 * on the task line at `taskIndex`. Pass `null` to clear. */
171export function setTaskPriorityAtIndex(
172 markdown: string,
173 taskIndex: number,
174 priority: TaskPriority | null
175): string {
176 return editTaskAtIndex(markdown, taskIndex, (match) => {
177 const prefix = match[1]
178 const checkChar = match[2]
179 const tailWithBracket = match[3]
180 if (!tailWithBracket.startsWith(']')) return null
181 const tail = tailWithBracket.slice(1)
182 const cleaned = tail.replace(PRIORITY_TOKEN_RE, '$1').replace(/\s{2,}/g, ' ')
183 let nextTail: string
184 if (priority) {
185 // Append at the end so the inline content reads naturally before
186 // the metadata token. Trim trailing whitespace so we don't
187 // accumulate spaces across repeated mutations.
188 nextTail = `${cleaned.replace(/\s+$/u, '')} !${priority}`
189 } else {
190 nextTail = cleaned.replace(/\s+$/u, '')
191 }
192 return `${prefix}${checkChar}]${nextTail}`
193 })
194}
195
196/** Replace, insert, or remove the `due:YYYY-MM-DD` token on the task
197 * line at `taskIndex`. Pass `null` to clear. */

Callers 2

store.tsFile · 0.90
tasklists.test.tsFile · 0.90

Calls 1

editTaskAtIndexFunction · 0.85

Tested by

no test coverage detected