export const tokenizeBlock = (paragraph: string) => { for (const block of blockTokens) { const openTest = block.rx.test(paragraph), closeTest = block.closeRx.test(paragraph); if (closeTest) return block.create(paragraph).type; if (!openTest) continue; return block.create(paragraph); } }; const blockTokens: { rx: RegExp; closeRx: RegExp; create: (line: string) => BlockToken; }[] = [ // this indicates that this is a grid block, all paragraphs within this block will be placed in a number of columns that match the number of sets of brackets are in this line { rx: /^(\[\]){2,}/g, closeRx: /\/\[\]/, create(line) { return { type: "grid", metadata: { columns: line.match(/\[\]/g)?.length, }, children: [], closed: false, uuid: crypto.randomUUID(), }; }, }, { rx: /^(\[\[)/, closeRx: /\]\]/, create() { return { type: "card", metadata: {}, children: [], closed: false, uuid: crypto.randomUUID(), }; }, }, { rx: /\[accordion\s?([a-z\s]*)\]/, closeRx: /\[\/accordion\]/, create(line) { const title = line.match(this.rx)?.at(1); return { type: "accordion", metadata: { title }, children: [], closed: false, uuid: crypto.randomUUID(), }; }, }, ];