diff --git a/src/lib/MathText.tsx b/src/lib/MathText.tsx index 03467bd..2eaed7d 100644 --- a/src/lib/MathText.tsx +++ b/src/lib/MathText.tsx @@ -33,7 +33,15 @@ const EDGE_END = /[\s،؛:!؟«»"'.=]+$/; // سمتِ خودشان می‌کشیدند، پس فهرست باز برعکس می‌شد. const LTR = { unicodeBidi: 'isolate-override', direction: 'ltr' } as const; -export function MathText({ text: raw }: { text: string }) { +// فرمولِ «واقعی» (نه عددِ تنها): نمادِ رابطه یا عمل دارد و دستِ‌کم چهار نویسه است. +const FORMULA = /[=<>≤≥≠∈∉⊂⊆∪∩+×÷^√∑∫]|[0-9۰-۹A-Za-z)][\s]*[−\-/][\s]*[0-9۰-۹A-Za-z(]/; + +/** + * `display`: فرمولِ وسطِ جمله‌ی فارسی در خطِ جدا و وسط‌چین می‌نشیند (سوال‌ها و درس‌ها)، تا + * چشم وسطِ فرمول به خطِ بعد نیفتد. عددِ تنها و عبارتِ کوتاهِ بدونِ نمادِ عمل داخلِ جمله می‌ماند. + * آزموده نشده: صفحه‌ی واقعیِ اپ در Chrome و Safari؛ فقط منطقِ تشخیص با نمونه‌های بانک سنجیده شد. + */ +export function MathText({ text: raw, display = false }: { text: string; display?: boolean }) { const text = plainPersian(plainMath(raw)); const out: React.ReactNode[] = []; const depth = bracketDepth(text); @@ -56,7 +64,13 @@ export function MathText({ text: raw }: { text: string }) { run = edge.run; if (!run || !HAS_MATH.test(run)) continue; out.push(text.slice(last, start + head.length)); - out.push({run}); + const before = text.slice(0, start + head.length), after = text.slice(start + head.length + run.length); + const inSentence = new RegExp(`[${LETTER}]`).test(before) || new RegExp(`[${LETTER}]`).test(after); + if (display && inSentence && run.trim().length >= 4 && FORMULA.test(run) && depth[start + head.length] === 0) { + out.push({run}); + } else { + out.push({run}); + } last = start + head.length + run.length; } } diff --git a/src/lib/StepText.tsx b/src/lib/StepText.tsx index 638f8c8..9ae83d8 100644 --- a/src/lib/StepText.tsx +++ b/src/lib/StepText.tsx @@ -28,17 +28,17 @@ export function parseNumbered(text: string): { lead: string; items: string[] } | export function StepText({ text, color, className = '' }: { text: string; color: string; className?: string }) { const list = parseNumbered(text); - if (!list) return

; + if (!list) return

; return (
- {list.lead &&

} + {list.lead &&

}
    {list.items.map((item, i) => (
  1. {toFa(i + 1)} - +
  2. ))}
diff --git a/src/screens/LessonScreen.tsx b/src/screens/LessonScreen.tsx index 34f8394..3202458 100644 --- a/src/screens/LessonScreen.tsx +++ b/src/screens/LessonScreen.tsx @@ -81,7 +81,7 @@ export function LessonScreen({ lessonId, nodeId }: { lessonId: number; nodeId?: {toFa(i + 1)} - {figs('step', i)} + {figs('step', i)} ))} diff --git a/src/screens/QuizScreen.tsx b/src/screens/QuizScreen.tsx index 1fdcaea..a7ff0d2 100644 --- a/src/screens/QuizScreen.tsx +++ b/src/screens/QuizScreen.tsx @@ -345,7 +345,7 @@ export function QuizScreen({ lessonId, nodeId }: { lessonId?: number; nodeId?: s
سوال {toFa(index + 1)}
-

+

{question.figure ?
: null}