( markdown: string, taskIndex: number, priority: TaskPriority | null )
| 169 | /** Replace, insert, or remove the priority token (`!high|!med|!low`) |
| 170 | * on the task line at `taskIndex`. Pass `null` to clear. */ |
| 171 | export 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. */ |
no test coverage detected