diff --git a/klausur-service/backend/smart_spell.py b/klausur-service/backend/smart_spell.py index 77fe7e8..e400474 100644 --- a/klausur-service/backend/smart_spell.py +++ b/klausur-service/backend/smart_spell.py @@ -534,6 +534,13 @@ class SmartSpellChecker: # --- Pass 3: Per-word correction --- parts: List[str] = [] + + # Preserve any leading text before the first token match + # (e.g., "(= " before "I won and he lost.") + first_start = tokens[0].start() if tokens else 0 + if first_start > 0: + parts.append(text[:first_start]) + for i, (word, sep) in enumerate(token_list): # Skip words inside IPA brackets (brackets land in separators) prev_sep = token_list[i - 1][1] if i > 0 else ""