Something went wrong. Try again.
Remanso is where your scattered thinking comes to rest. remanso.space
Something went wrong. Try again.
12345678910111213141516171819202122232425262728const CHECKBOX_PATTERN = /\[([ xX])\]/g
// Rewrite the nth `[ ]` / `[x]` in the markdown source. The index comes from// the rendered DOM, which lists checkboxes in source order, so the two stay// aligned as long as we count the same way.export const setCheckboxInMarkdown = ( markdown: string, index: number, checked: boolean): string => { let currentIndex = 0
return markdown.replace(CHECKBOX_PATTERN, (match) => { if (currentIndex++ === index) { return checked ? "[x]" : "[ ]" } return match })}
export const findCheckboxIndex = ( container: Element, checkbox: HTMLInputElement): number => { const allCheckboxes = container.querySelectorAll('input[type="checkbox"]') return Array.from(allCheckboxes).indexOf(checkbox)}