| 264 | }); |
| 265 | |
| 266 | function toggleNthTask(md: string, index: number): string { |
| 267 | let counter = 0; |
| 268 | return md.replace( |
| 269 | /(^|\n)([\t ]*)([-*]|\d+\.)[\t ]+\[( |x|X)\]/g, |
| 270 | (match, prefix: string, indent: string, bullet: string, mark: string) => { |
| 271 | if (counter === index) { |
| 272 | const next = mark.toLowerCase() === 'x' ? ' ' : 'x'; |
| 273 | counter++; |
| 274 | return `${prefix}${indent}${bullet} [${next}]`; |
| 275 | } |
| 276 | counter++; |
| 277 | return match; |
| 278 | }, |
| 279 | ); |
| 280 | } |
| 281 | |
| 282 | // Track expected content after checkbox toggles to skip re-renders |
| 283 | // Key: dataTestId, Value: expected content string |