Open History to see the last commit
1export type NoteBlock =
2 | { type: "heading"; text: string }
3 | { type: "paragraph"; text: string }
4 | { type: "bullet"; text: string }
5 | { type: "checklist"; text: string; checked: boolean };
6
7/** Turns a note body (one block per line) into renderable blocks. */
8export function parseNoteBody(body: string): NoteBlock[] {
9 return body
10 .split("\n")
11 .filter((line) => line.trim() !== "")
12 .map((line): NoteBlock => {
13 if (line.startsWith("# ")) return { type: "heading", text: line.slice(2) };
14 if (line.startsWith("- ")) return { type: "bullet", text: line.slice(2) };
15 if (line.startsWith("[ ] "))
16 return { type: "checklist", text: line.slice(4), checked: false };
17 if (line.startsWith("[x] ")) return { type: "checklist", text: line.slice(4), checked: true };
18 return { type: "paragraph", text: line };
19 });
20}
21
22/** The grey preview text shown under a note's title in the list. */
23export function noteSnippet(body: string): string {
24 const [first] = parseNoteBody(body);
25 return first?.text ?? "No additional text";
26}