Skip to content

🎥 Make videos programmatically with React

Add stripMarkdownFences utility function

ASchwad14f6401fc2a7
diff --git a/packages/template-prompt-to-motion-graphics/src/helpers/sanitize-response.ts b/packages/template-prompt-to-motion-graphics/src/helpers/sanitize-response.ts
index 479dc1b630..a9fa9a1f0d 100644
--- a/packages/template-prompt-to-motion-graphics/src/helpers/sanitize-response.ts
+++ b/packages/template-prompt-to-motion-graphics/src/helpers/sanitize-response.ts
@@ -3,6 +3,17 @@ export interface ValidationResult {
error: string | null;
}
+/**
+ * Strip markdown code fences from a string.
+ * Handles ```tsx, ```ts, ```jsx, ```js and plain ``` fences.
+ */
+export function stripMarkdownFences(code: string): string {
+ let result = code;
+ result = result.replace(/^```(?:tsx?|jsx?)?\n?/, "");
+ result = result.replace(/\n?```\s*$/, "");
+ return result.trim();
+}
+
/**
* Lightweight validation to check if GPT response contains JSX content.
* This is a fallback check after the LLM pre-validation.