From cb814d94fa47441748c70096f4ec4b805e2dee50 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Sat, 14 Mar 2026 00:33:14 +0100 Subject: [PATCH] Add function to sanitize AI response --- src/App.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/App.tsx b/src/App.tsx index 03404ae..2b12efd 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -384,6 +384,18 @@ function getAiPromptTemplateLabel(template: AiPromptTemplate) { return template.title.trim() || "Untitled Prompt"; } +function sanitizeAiResponse(text: string) { + const normalized = text.trim(); + const markdownFenceMatch = normalized.match( + /```(?:markdown|md)\b[^\n\r]*\r?\n?([\s\S]*?)```/i + ); + if (!markdownFenceMatch) { + return normalized; + } + + return markdownFenceMatch[1].trim(); +} + const graphemeSegmenter = typeof Intl !== "undefined" && "Segmenter" in Intl ? new Intl.Segmenter(undefined, { granularity: "grapheme" })