(content: string)
| 21 | } |
| 22 | |
| 23 | function generateTableOfContents(content: string): string { |
| 24 | // Extract headings from the markdown content |
| 25 | const headingRegex = /^(#{2,6})\s+(.+)$/gm |
| 26 | const headings: { level: number; text: string; anchor: string }[] = [] |
| 27 | let match |
| 28 | |
| 29 | while ((match = headingRegex.exec(content)) !== null) { |
| 30 | const level = match[1].length |
| 31 | const text = match[2].trim() |
| 32 | const anchor = generateAnchor(text) |
| 33 | |
| 34 | headings.push({ level, text, anchor }) |
| 35 | } |
| 36 | |
| 37 | if (headings.length === 0) { |
| 38 | return "" |
| 39 | } |
| 40 | |
| 41 | // Build nested TOC structure |
| 42 | const tocItems = buildTocStructure(headings) |
| 43 | |
| 44 | // Generate TOC markdown |
| 45 | let toc = "## Table of Contents\n\n" |
| 46 | toc += generateTocMarkdown(tocItems) |
| 47 | toc += "\n" |
| 48 | |
| 49 | return toc |
| 50 | } |
| 51 | |
| 52 | function generateAnchor(text: string): string { |
| 53 | return text |
no test coverage detected