MCPcopy Index your code
hub / github.com/Nutlope/llamacoder / extractAllCodeBlocks

Function extractAllCodeBlocks

lib/utils.ts:57–84  ·  view source on GitHub ↗
(input: string)

Source from the content-addressed store, hash-verified

55}
56
57export 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
86function parseFileName(fileName: string): { name: string; extension: string } {
87 // Split the string at the last dot

Callers 7

SharePageFunction · 0.90
ChatLogFunction · 0.90
AssistantMessageFunction · 0.90
fFunction · 0.90
getFilesFromMessageFunction · 0.90
CodeViewerFunction · 0.90
getFilesFromMessageFunction · 0.90

Calls 1

parseFenceTagFunction · 0.85

Tested by

no test coverage detected