( markdown: string, taskIndex: number, waiting: boolean )
| 139 | * separating space; removing collapses any extra whitespace it left |
| 140 | * behind so the line stays tidy. */ |
| 141 | export function setTaskWaitingAtIndex( |
| 142 | markdown: string, |
| 143 | taskIndex: number, |
| 144 | waiting: boolean |
| 145 | ): string { |
| 146 | return editTaskAtIndex(markdown, taskIndex, (match) => { |
| 147 | const prefix = match[1] |
| 148 | const checkChar = match[2] |
| 149 | const tailWithBracket = match[3] |
| 150 | if (!tailWithBracket.startsWith(']')) return null |
| 151 | const tail = tailWithBracket.slice(1) |
| 152 | const has = WAITING_TOKEN_RE.test(tail) |
| 153 | let nextTail = tail |
| 154 | if (waiting && !has) { |
| 155 | nextTail = `${tail.replace(/\s+$/u, '')} @waiting` |
| 156 | } else if (!waiting && has) { |
| 157 | nextTail = tail |
| 158 | .replace(WAITING_TOKEN_RE, '$1') |
| 159 | .replace(/\s{2,}/g, ' ') |
| 160 | .replace(/\s+$/u, '') |
| 161 | } |
| 162 | return `${prefix}${checkChar}]${nextTail}` |
| 163 | }) |
| 164 | } |
| 165 | |
| 166 | const PRIORITY_TOKEN_RE = /(^|\s)!(?:high|med|medium|low|h|m|l)\b/i |
| 167 | const DUE_TOKEN_RE = /(^|\s)due:\S+/i |
no test coverage detected