Browse Source

fix(custom-content): preserve markdown formatting in text cleanup

The cleanupText() function was too aggressive, destroying markdown:
- Removed all leading whitespace (breaks indentation, lists, code blocks)
- Collapsed multiple spaces (breaks markdown spacing rules)
- Removed trailing whitespace (breaks markdown line breaks with 2 spaces)

New minimal cleanup preserves markdown formatting:
- Limits excessive blank lines (max 3 consecutive newlines)
- Removes only trailing spaces/tabs from lines
- Preserves leading whitespace for indentation
- Preserves newlines for paragraphs and spacing

Fixes broken markdown/plain text formatting in custom content entries.
Fszontagh 4 months ago
parent
commit
b0729e428c
1 changed files with 4 additions and 6 deletions
  1. 4 6
      shopcall.ai-main/src/components/CustomContentTextEntry.tsx

+ 4 - 6
shopcall.ai-main/src/components/CustomContentTextEntry.tsx

@@ -34,14 +34,12 @@ const turndownService = new TurndownService({
 // Remove image tags from markdown
 turndownService.remove('img');
 
-// Clean up text: remove excessive whitespace, newlines, tabs
+// Clean up text: minimal cleanup to preserve markdown formatting
 const cleanupText = (text: string): string => {
   return text
-    .replace(/\t/g, ' ')              // Replace tabs with spaces
-    .replace(/[ ]+/g, ' ')            // Replace multiple spaces with single space
-    .replace(/\n{3,}/g, '\n\n')       // Replace 3+ newlines with 2 newlines
-    .replace(/^\s+|\s+$/gm, '')       // Trim whitespace from each line
-    .trim();                           // Trim overall
+    .replace(/\n{4,}/g, '\n\n\n')     // Limit to max 3 consecutive newlines (preserve paragraph spacing)
+    .replace(/[ \t]+$/gm, '')         // Remove trailing spaces/tabs from each line
+    .trim();                           // Trim overall leading/trailing whitespace
 };
 
 export function CustomContentTextEntry({ onSuccess }: CustomContentTextEntryProps) {