// Name: Format Clipboard for LogSeq // Description: Converts clipboard text into LogSeq-friendly tab-indented bullet points. // Author: tayiorbeii // GitHub: tayiorbeii import "@johnlindquist/kit" const raw = (await paste()) || "" if (!raw.trim()) { await notify("Clipboard is empty") exit() } const lines = raw.replace(/\r\n/g, "\n").split("\n") const bulletRegex = /^(?<indent>[ \t]*)(?<marker>[-*•·◦–—]|(?:\d+|[a-zA-Z]+)[\.\)])\s+(?<text>.*)$/ const out: string[] = [] for (const line of lines) { const r = line.replace(/\s+$/, "") if (!r.trim()) continue const m = r.match(bulletRegex) as unknown as | { groups?: { indent?: string; text?: string } } | null if (m?.groups) { const indentStr = m.groups.indent || "" const spaces = (indentStr.match(/ /g) || []).length const tabs = (indentStr.match(/\t/g) || []).length const level = tabs + Math.floor(spaces / 2) const text = (m.groups.text || "").trim() out.push(`${"\t".repeat(level)}- ${text}`) } else { out.push(`- ${r.trim()}`) } } const formatted = out.join("\n") await copy(formatted) await notify("Formatted clipboard for LogSeq. Ready to paste!")