* Extract document sections from raw markdown content by finding H2 headings. * Used as a fallback when the parser cannot extract YAML.
(content: string)
| 115 | * Used as a fallback when the parser cannot extract YAML. |
| 116 | */ |
| 117 | function extractSectionsFromContent(content: string): Array<{ heading: string; content: string }> { |
| 118 | const lines = content.split('\n'); |
| 119 | const sections: Array<{ heading: string; content: string }> = []; |
| 120 | const headingPattern = /^## (.+)$/; |
| 121 | |
| 122 | let currentStart = 0; |
| 123 | let currentHeading = ''; |
| 124 | |
| 125 | for (let i = 0; i < lines.length; i++) { |
| 126 | const line = lines[i]; |
| 127 | if (!line) continue; |
| 128 | |
| 129 | const match = headingPattern.exec(line); |
| 130 | if (match) { |
| 131 | // Push previous section |
| 132 | if (i > 0) { |
| 133 | sections.push({ |
| 134 | heading: currentHeading, |
| 135 | content: lines.slice(currentStart, i).join('\n'), |
| 136 | }); |
| 137 | } |
| 138 | currentHeading = match[1] ?? ''; |
| 139 | currentStart = i; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | // Push final section |
| 144 | sections.push({ |
| 145 | heading: currentHeading, |
| 146 | content: lines.slice(currentStart).join('\n'), |
| 147 | }); |
| 148 | |
| 149 | return sections; |
| 150 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…