(input: string)
| 55 | } |
| 56 | |
| 57 | export function extractAllCodeBlocks(input: string): Array<{ |
| 58 | code: string; |
| 59 | language: string; |
| 60 | path: string; |
| 61 | fullMatch: string; |
| 62 | }> { |
| 63 | const codeBlockRegex = /```([^\n]*)\n([\s\S]*?)\n```/g; |
| 64 | const files: Array<{ |
| 65 | code: string; |
| 66 | language: string; |
| 67 | path: string; |
| 68 | fullMatch: string; |
| 69 | }> = []; |
| 70 | |
| 71 | let match; |
| 72 | while ((match = codeBlockRegex.exec(input)) !== null) { |
| 73 | const fenceTag = match[1] || ""; // e.g. "tsx{path=src/App.tsx}" |
| 74 | const code = match[2]; // The actual code block content |
| 75 | const fullMatch = match[0]; // Entire matched string including backticks |
| 76 | |
| 77 | // Parse language and path |
| 78 | const { language, path } = parseFenceTag(fenceTag); |
| 79 | |
| 80 | files.push({ code, language, path, fullMatch }); |
| 81 | } |
| 82 | |
| 83 | return files; |
| 84 | } |
| 85 | |
| 86 | function parseFileName(fileName: string): { name: string; extension: string } { |
| 87 | // Split the string at the last dot |
no test coverage detected