Tutor/answers: bare subscripts (S_n, a_1) become Unicode; migration 0022 re-cleans DB text

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-12 12:18:46 +03:30
parent e662914efc
commit b075b93f2a
5 changed files with 31 additions and 4 deletions

View File

@@ -99,7 +99,8 @@ def convert(text: str) -> str:
s = re.sub(r'\^\(((?:[^()]|\([^()]*\))*)\)', lambda m: _try(m[1], _SUP) or f' به توانِ ({m[1].strip()}) ', s)
s = re.sub(r'(?<=[A-Za-z0-9۰-۹\)₀-₉ₐ-ₜᵢⱼ])\^([A-Za-zα-ωΑ-Ω□▢])(?![A-Za-z0-9۰-۹])', lambda m: _try(m[1], _SUP) or f' به توانِ {m[1]} ', s)
s = re.sub(r'\^([+\-−]?[0-9۰-۹]+)', lambda m: _try(m[1], _SUP) or m[0], s)
s = s = re.sub(r'(?<=[A-Za-z\)∫Σ∏])_([0-9۰-۹]+|[A-Za-z]{1,4}[0-9۰-۹]?)', lambda m: ''.join(_SUB.get(ch, ch) for ch in m[1]), s)
s = s = re.sub(r'((?<![A-Za-z0-9_])[A-Za-z]|log|ln|lim|[)∫Σ∏])_([0-9۰-۹]+[A-Za-z]?|[A-Za-z]{1,4}[0-9۰-۹]?)(?![A-Za-z0-9_])',
lambda m: (f'log پایه‌ی {m[2]}' if m[1] == 'log' and any(ch not in _SUB for ch in m[2]) else m[1] + ''.join(_SUB.get(ch, ch) for ch in m[2])), s)
s = re.sub(r'log_([A-Za-z])(?![A-Za-z0-9])', lambda m: m[0] if m[1] in _SUB else f'log پایه‌ی {m[1]}', s)
s = re.sub(r'(?<=\S) {2,}(?=\S)', ' ', s)
s = re.sub(r'(?<=[A-Za-z])_\(([^()]*)\)', r'(\1)', s)