respect the \n in latexInput

This commit is contained in:
Majd_dk 2025-08-17 15:15:10 +03:00
parent 308d399dae
commit ffb677c28b
3 changed files with 23 additions and 7 deletions

View File

@ -142,21 +142,26 @@ const LaTeXInputMemo: React.FC<any> = React.memo(
{showPreview && ( {showPreview && (
<div className="showPreviewInput"> <div className="showPreviewInput">
{Preview?.map((item: any, index: number) => { {Preview?.map((item: any, index: number,items) => {
if (item?.isLatex) { if (item?.isLatex) {
return ( return (
<span <div
dir="ltr" dir="ltr"
key={index} key={index}
onClick={() => handleEditModal(item)}
className="LatexPreview" className="LatexPreview"
> >
<LatexPreview latex={item?.text} /> <LatexPreview latex={item?.text} />
</span> </div>
); );
} }
return <div key={index}>{item?.text}</div>; return <div key={index}
style={{
width: item?.text?.includes("\n") && items.length > 1 ? "100%" : undefined,
whiteSpace: "pre-wrap",
}}
>{ items[index -1]?.isLatex ? item?.text?.replace(/\n/, ""):item?.text}</div>;
})} })}
</div> </div>
)} )}

View File

@ -36,6 +36,13 @@
border: 1px solid #d9d9d9; border: 1px solid #d9d9d9;
padding: 5px 10px; padding: 5px 10px;
row-gap: 0px; row-gap: 0px;
white-space:pre-line;
overflow-y: auto;
resize: none;
// height: 165px;
min-height: 164px;
max-height: 270px;
} }
.addMML { .addMML {
all: unset; all: unset;

View File

@ -7,15 +7,19 @@ interface TextLatexPart {
export const parseTextAndLatex = (input: string): TextLatexPart[] => { export const parseTextAndLatex = (input: string): TextLatexPart[] => {
const result: TextLatexPart[] = []; const result: TextLatexPart[] = [];
console.log(input)
const parts = input?.split(/(\$\$[^$]+\$\$)/g); const parts = input?.split(/(\$\$[^$]+\$\$)/g);
console.log(parts)
parts.forEach((part, index) => { parts.forEach((part, index) => {
if (part.startsWith("$$") && part.endsWith("$$")) { if (part.startsWith("$$") && part.endsWith("$$")) {
result.push({ text: part.slice(2, -2), isLatex: true, key: index }); result.push({ text: part.slice(2, -2), isLatex: true, key: index });
} else if (part.trim()) { }
else {
result.push({ text: part, isLatex: false, key: index }); result.push({ text: part, isLatex: false, key: index });
} }
}); });
console.log(result)
return result; return result;
}; };