From f9a5f7237eb259250157829acf3b2edbac04e62f Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sun, 11 May 2025 13:34:20 +0545 Subject: [PATCH] Improve text formatting logic --- VoiceInk/Whisper/WhisperTextFormatter.swift | 29 +++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/VoiceInk/Whisper/WhisperTextFormatter.swift b/VoiceInk/Whisper/WhisperTextFormatter.swift index 5fe7687..8944f22 100644 --- a/VoiceInk/Whisper/WhisperTextFormatter.swift +++ b/VoiceInk/Whisper/WhisperTextFormatter.swift @@ -4,22 +4,6 @@ struct WhisperTextFormatter { static func format(_ text: String) -> String { var formattedText = text - // First, replace commas with periods before new line/paragraph commands - let commaPatterns = [ - // Replace comma before new paragraph - (pattern: ",\\s*new\\s+paragraph", replacement: ". new paragraph"), - // Replace comma before new line - (pattern: ",\\s*new\\s+line", replacement: ". new line") - ] - - for (pattern, replacement) in commaPatterns { - formattedText = formattedText.replacingOccurrences( - of: pattern, - with: replacement, - options: [.regularExpression, .caseInsensitive] - ) - } - // Handle single-word variants let singleWordPatterns = [ (pattern: "\\b(newline)\\b", replacement: "new line"), @@ -33,6 +17,19 @@ struct WhisperTextFormatter { options: [.regularExpression, .caseInsensitive] ) } + + // Insert a period before 'new line' or 'new paragraph' if not preceded by punctuation + let punctuationInsertPatterns = [ + (pattern: "(?