import { renderLink } from './parseTextFormats'; export interface ComponentBlock { type: 'button'; html: string; startLine: number; endLine: number; } export interface ComponentsParseResult { blocks: ComponentBlock[]; processedLines: Set; } const BUTTON_REGEX = /^\[button\((.+?)\)\]$/; export function parseComponents(lines: string[]): ComponentsParseResult { const blocks: ComponentBlock[] = []; const processedLines = new Set(); lines.forEach((line, i) => { const trimmed = line.trim(); const btnMatch = trimmed.match(BUTTON_REGEX); if (btnMatch) { const inner = btnMatch[1]; const pipeIndex = inner.indexOf('|'); if (pipeIndex !== -1) { const rawTarget = inner.slice(0, pipeIndex).trim(); const rawText = inner.slice(pipeIndex + 1).trim(); const html = renderLink(rawTarget, rawText, 'bogam-link-button'); blocks.push({ type: 'button', html, startLine: i, endLine: i }); processedLines.add(i); return; } } }); return { blocks, processedLines }; }