Files
famapp/src/components/rich-text/toggle-checklist.ts
T
ginnoir a4be5d5061 feat(notes): rich-text editor with tiptap (task 85)
Replace plain textarea with shared tiptap editor and sanitized html rendering.

Adds interactive checklists on read surfaces and mobile overflow fixes.
2026-07-04 19:25:15 -05:00

29 lines
835 B
TypeScript

const TASK_ITEM_RE = /<li([^>]*data-type="taskItem"[^>]*)>/gi;
export function toggleTaskItemInHtml(html: string, taskIndex: number, checked: boolean): string {
let index = 0;
return html.replace(TASK_ITEM_RE, (match, attrs: string) => {
const current = index;
index += 1;
if (current !== taskIndex) return match;
const checkedValue = checked ? "true" : "false";
let nextAttrs = attrs;
if (/data-checked="(?:true|false)"/i.test(nextAttrs)) {
nextAttrs = nextAttrs.replace(
/data-checked="(?:true|false)"/i,
`data-checked="${checkedValue}"`,
);
} else {
nextAttrs = `${nextAttrs} data-checked="${checkedValue}"`;
}
return `<li${nextAttrs}>`;
});
}
export function countTaskItems(html: string): number {
return [...html.matchAll(TASK_ITEM_RE)].length;
}