MathText: last-line guard that turns stray LaTeX/markdown into plain Unicode

This commit is contained in:
2026-10-12 12:15:31 +03:30
parent cf2a3251dd
commit f2263e6dff
2 changed files with 80 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { Fragment } from 'react';
import { plainMath } from './plainMath';
/**
* متنِ فارسی که ریاضی لایش است («عدد −۱ می‌شود»، «رأس (۱، −۴) است»).
@@ -32,7 +33,8 @@ const EDGE_END = /[\s،؛:!؟«»"'.=]+$/;
// سمتِ خودشان می‌کشیدند، پس فهرست باز برعکس می‌شد.
const LTR = { unicodeBidi: 'isolate-override', direction: 'ltr' } as const;
export function MathText({ text }: { text: string }) {
export function MathText({ text: raw }: { text: string }) {
const text = plainMath(raw);
const out: React.ReactNode[] = [];
const depth = bracketDepth(text);
let last = 0, i = 0;