// HTML comments are invisible on GitHub; the headings/fences remain normal Markdown. const LABELS = new Map([ ['TypeScript', 'typescript'], ['Rust', 'rust'], ['TypeScript / Electron', 'typescript'], ['Rust / Tauri', 'rust'], ]); const INSTALL_LABELS = new Map([['Codex', 'codex'], ['Claude Code', 'claude']]); export function renderCodeTabs(markdown, page) { let group = 0; const output = markdown.replace(/^\s*\n([\s\S]*?)^/gm, (_, kind, body) => { const install = kind === 'install-tabs'; const labels = install ? INSTALL_LABELS : LABELS; const parts = [...body.matchAll(/^### (.+)\n([\s\S]*?)(?=^### |$(?![\s\S]))/gm)]; if (parts.length !== 2 || parts.some(p => !labels.has(p[1].trim()))) throw Error(`Expected ${install ? 'Codex and Claude Code' : 'TypeScript and Rust'} in SDK tabs: ${page}`); const keys = parts.map(p => labels.get(p[1].trim())); if (new Set(keys).size !== 2 || !body.trimStart().startsWith('### ')) throw Error(`Duplicate or malformed SDK tabs: ${page}`); const id = `${page}-code-${++group}`; const buttons = parts.map((p, i) => ``).join('\n'); const panels = parts.map((p, i) => `
\n\n

${p[1].trim()}

\n\n${p[2].trim()}\n\n
`).join('\n\n'); // Without JavaScript, both labelled examples remain readable. return `
\n\n\n${panels}\n\n
`; }); if (/^/m.test(output)) throw Error(`Unclosed SDK tabs: ${page}`); return output.replace(/^```rust,(?:ignore|no_run)\s*$/gm, '```rust'); }