diff --git a/client/package-lock.json b/client/package-lock.json index edc30d8..582c84c 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -9463,14 +9463,13 @@ } }, "node_modules/katex": { - "version": "0.16.11", - "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.11.tgz", - "integrity": "sha512-RQrI8rlHY92OLf3rho/Ts8i/XvjgguEjOkO1BEXcU3N8BqPpSzBNwV/G0Ukr+P/l3ivvJUE/Fa/CwbS6HesGNQ==", + "version": "0.16.21", + "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.21.tgz", + "integrity": "sha512-XvqR7FgOHtWupfMiigNzmh+MgUVmDGU2kXZm899ZkPfcuoPuFxyHmXsgATDpFZDAXCI8tvinaVcDo8PIIJSo4A==", "funding": [ "https://opencollective.com/katex", "https://github.com/sponsors/katex" ], - "license": "MIT", "dependencies": { "commander": "^8.3.0" }, @@ -10326,16 +10325,15 @@ "license": "MIT" }, "node_modules/nanoid": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.8.tgz", - "integrity": "sha512-TcJPw+9RV9dibz1hHUzlLVy8N4X9TnwirAjrU08Juo6BNKggzVfP2ZJ/3ZUSq15Xl5i85i+Z89XBO90pB2PghQ==", + "version": "5.0.9", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.9.tgz", + "integrity": "sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==", "funding": [ { "type": "github", "url": "https://github.com/sponsors/ai" } ], - "license": "MIT", "bin": { "nanoid": "bin/nanoid.js" }, @@ -12634,10 +12632,9 @@ } }, "node_modules/vite": { - "version": "5.4.10", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.10.tgz", - "integrity": "sha512-1hvaPshuPUtxeQ0hsVH3Mud0ZanOLwVTneA1EgbAM5LhaZEqyPWGRQ7BtaMvUrTDeEaC8pxtj6a6jku3x4z6SQ==", - "license": "MIT", + "version": "5.4.14", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz", + "integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==", "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", diff --git a/client/src/components/GiftTemplate/templates/TextType.ts b/client/src/components/GiftTemplate/templates/TextType.ts index 02a7a14..eae1320 100644 --- a/client/src/components/GiftTemplate/templates/TextType.ts +++ b/client/src/components/GiftTemplate/templates/TextType.ts @@ -35,7 +35,7 @@ export default function textType({ text }: TextTypeOptions) { case 'moodle': case 'plain': // Replace newlines with
tags - return formatText.replace(/(?:\r\n|\r|\n)/g, '
'); + return replaceNewlinesOutsideSVG(formatText); case 'html': // Strip outer paragraph tags (not a great approach with regex) return formatText.replace(/(^

)(.*?)(<\/p>)$/gm, '$2'); @@ -46,3 +46,25 @@ export default function textType({ text }: TextTypeOptions) { throw new Error(`Unsupported text format: ${text.format}`); } } + +// Function to replace \n outside of SVG paths +function replaceNewlinesOutsideSVG(text: string): string { + const svgPathRegex = /]*d="([^"]*)"[^>]*>/g; + let result = ''; + let lastIndex = 0; + + // Iterate over all SVG paths + text.replace(svgPathRegex, (match, _p1, offset) => { + // Append text before the SVG path, replacing \n with
+ result += text.slice(lastIndex, offset).replace(/(?:\r\n|\r|\n)/g, '
'); + // Append the SVG path without replacing \n + result += match; + // Update the last index + lastIndex = offset + match.length; + return match; + }); + + // Append the remaining text, replacing \n with
+ result += text.slice(lastIndex).replace(/(?:\r\n|\r|\n)/g, '
'); + return result; +} diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 3c251e0..0000000 --- a/package-lock.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "EvalueTonSavoir", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "dependencies": { - "dompurify": "^3.2.3" - } - }, - "node_modules/@types/trusted-types": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/@types/trusted-types/-/trusted-types-2.0.7.tgz", - "integrity": "sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==", - "license": "MIT", - "optional": true - }, - "node_modules/dompurify": { - "version": "3.2.3", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-3.2.3.tgz", - "integrity": "sha512-U1U5Hzc2MO0oW3DF+G9qYN0aT7atAou4AgI0XjWz061nyBPbdxkfdhfy5uMgGn6+oLFCfn44ZGbdDqCzVmlOWA==", - "license": "(MPL-2.0 OR Apache-2.0)", - "optionalDependencies": { - "@types/trusted-types": "^2.0.7" - } - } - } -} diff --git a/package.json b/package.json deleted file mode 100644 index a969a9f..0000000 --- a/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "dompurify": "^3.2.3" - } -}