| 1 | /** |
| 2 | * Extracts file paths from markdown code blocks |
| 3 | */ |
| 4 | export function extractPathsFromCodeBlocks(content: string): string[] { |
| 5 | // Match: |
| 6 | // 1. Starting ``` |
| 7 | // 2. Optional language identifier |
| 8 | // 3. Required whitespace |
| 9 | // 4. File path (captured) that must contain a dot and extension |
| 10 | const codeBlockRegex = /```(?:[\w-+#]+)?\s+([^\s\n()]+\.[a-zA-Z0-9]+)/g; |
| 11 | const paths: string[] = []; |
| 12 | let match; |
| 13 | |
| 14 | while ((match = codeBlockRegex.exec(content)) !== null) { |
| 15 | const path = match[1]; |
| 16 | if (path && !path.startsWith("```")) { |
| 17 | paths.push(path); |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | return paths; |
| 22 | } |