MCPcopy Index your code
hub / github.com/cloudflare/agents / stripCodeFences

Function stripCodeFences

packages/codemode/src/normalize.ts:7–12  ·  view source on GitHub ↗

* Strip markdown code fences that LLMs commonly wrap code in. * Handles ```js, ```javascript, ```typescript, ```ts, or bare ```.

(code: string)

Source from the content-addressed store, hash-verified

5 * Handles ```js, ```javascript, ```typescript, ```ts, or bare ```.
6 */
7function stripCodeFences(code: string): string {
8 const fenced =
9 /^```(?:js|javascript|typescript|ts|tsx|jsx)?\s*\n([\s\S]*?)```\s*$/;
10 const match = code.match(fenced);
11 return match ? match[1] : code;
12}
13
14export function normalizeCode(code: string): string {
15 const trimmed = stripCodeFences(code.trim());

Callers 1

normalizeCodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected