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.
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user