From cbd3698b58b3db7dfbbf6b852f85b93f14db2f5f Mon Sep 17 00:00:00 2001 From: Majd_dk Date: Sun, 28 Sep 2025 11:14:59 +0300 Subject: [PATCH] add switch For more than line in MML --- src/Components/LatextInput/AddLaTexModal.tsx | 18 ++++++++++++++++-- src/utils/parseTextAndLatex.ts | 6 ++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Components/LatextInput/AddLaTexModal.tsx b/src/Components/LatextInput/AddLaTexModal.tsx index 42170a2..c30ac2c 100644 --- a/src/Components/LatextInput/AddLaTexModal.tsx +++ b/src/Components/LatextInput/AddLaTexModal.tsx @@ -1,10 +1,11 @@ -import { Modal } from "antd"; +import { Modal, Switch } from "antd"; import TextArea from "antd/es/input/TextArea"; import { useFormikContext } from "formik"; import React, { useState } from "react"; import { convertMathMLToLaTeX } from "../../utils/convertMathMLToLaTeX"; import { useTranslation } from "react-i18next"; import { toast } from "react-toastify"; +import ValidationField from "../ValidationField/ValidationField"; const AddLaTexModal = ({ name, @@ -22,19 +23,27 @@ const AddLaTexModal = ({ setCurrentValue: (value: string) => void; }) => { const { values, setFieldValue, getFieldProps } = useFormikContext(); + const [isSwitchActive,setIsSwitchActive] = useState(false) + + const onChange = (checked: boolean) => { + setIsSwitchActive(checked) +}; const currentValue = getFieldProps(name).value; const handleOk = () => { const oldValue = currentValue ?? ""; const newLatex = convertMathMLToLaTeX(Latex) - const final = oldValue + " $$ " + newLatex + " $$ " + const final = oldValue + (isSwitchActive ? " $$$ " + newLatex + " $$$ " : " $$ " + newLatex + " $$ ") setFieldValue(name, final); setCurrentValue(final); setLatex(""); + setIsSwitchActive(false) setIsModalOpen(false); + }; const handleCancel = () => { + setIsSwitchActive(false) setIsModalOpen(false); setLatex(""); }; @@ -65,6 +74,11 @@ const AddLaTexModal = ({ onChange={handleChangeInputLatex} value={Latex} /> +
+ + + +
{t("practical.cancel")} diff --git a/src/utils/parseTextAndLatex.ts b/src/utils/parseTextAndLatex.ts index 7e17803..8baea29 100644 --- a/src/utils/parseTextAndLatex.ts +++ b/src/utils/parseTextAndLatex.ts @@ -8,12 +8,14 @@ interface TextPart { export const parseTextAndLatex = (input: string = ""): TextPart[] => { const out: TextPart[] = []; - const parts = input.split(/(\$\$[\s\S]+?\$\$|<>[\s\S]+?<>)/g); + const parts = input.split(/(\$\$\$[\s\S]+?\$\$\$|\$\$[\s\S]+?\$\$|<>[\s\S]+?<>)/g); parts.forEach((part, index) => { if (!part) return; - if (part.startsWith("$$") && part.endsWith("$$")) { + if (part.startsWith("$$$") && part.endsWith("$$$")) { + out.push({ text: part.slice(3, -3), isLatex: true, isImage: false, key: index }); + }else if (part.startsWith("$$") && part.endsWith("$$")) { out.push({ text: part.slice(2, -2), isLatex: true, isImage: false, key: index }); } else if (part.startsWith("<>") && part.endsWith("<>")) { const url = part.slice("<>".length, -"<>".length).trim();