Merge pull request #213 from ets-cfuhrman-pfe/fuhrmanator/issue201
Some checks are pending
CI/CD Pipeline for Backend / build_and_push_backend (push) Waiting to run
CI/CD Pipeline for Nginx Router / build_and_push_nginx (push) Waiting to run
CI/CD Pipeline for Frontend / build_and_push_frontend (push) Waiting to run
Tests / tests (client) (push) Waiting to run
Tests / tests (server) (push) Waiting to run

Fixes #201
This commit is contained in:
Christopher (Cris) Fuhrman 2025-01-28 09:39:09 -05:00 committed by GitHub
commit cd96cad26d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 32 additions and 46 deletions

View file

@ -9463,14 +9463,13 @@
} }
}, },
"node_modules/katex": { "node_modules/katex": {
"version": "0.16.11", "version": "0.16.21",
"resolved": "https://registry.npmjs.org/katex/-/katex-0.16.11.tgz", "resolved": "https://registry.npmjs.org/katex/-/katex-0.16.21.tgz",
"integrity": "sha512-RQrI8rlHY92OLf3rho/Ts8i/XvjgguEjOkO1BEXcU3N8BqPpSzBNwV/G0Ukr+P/l3ivvJUE/Fa/CwbS6HesGNQ==", "integrity": "sha512-XvqR7FgOHtWupfMiigNzmh+MgUVmDGU2kXZm899ZkPfcuoPuFxyHmXsgATDpFZDAXCI8tvinaVcDo8PIIJSo4A==",
"funding": [ "funding": [
"https://opencollective.com/katex", "https://opencollective.com/katex",
"https://github.com/sponsors/katex" "https://github.com/sponsors/katex"
], ],
"license": "MIT",
"dependencies": { "dependencies": {
"commander": "^8.3.0" "commander": "^8.3.0"
}, },
@ -10326,16 +10325,15 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/nanoid": { "node_modules/nanoid": {
"version": "5.0.8", "version": "5.0.9",
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.8.tgz", "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-5.0.9.tgz",
"integrity": "sha512-TcJPw+9RV9dibz1hHUzlLVy8N4X9TnwirAjrU08Juo6BNKggzVfP2ZJ/3ZUSq15Xl5i85i+Z89XBO90pB2PghQ==", "integrity": "sha512-Aooyr6MXU6HpvvWXKoVoXwKMs/KyVakWwg7xQfv5/S/RIgJMy0Ifa45H9qqYy7pTCszrHzP21Uk4PZq2HpEM8Q==",
"funding": [ "funding": [
{ {
"type": "github", "type": "github",
"url": "https://github.com/sponsors/ai" "url": "https://github.com/sponsors/ai"
} }
], ],
"license": "MIT",
"bin": { "bin": {
"nanoid": "bin/nanoid.js" "nanoid": "bin/nanoid.js"
}, },
@ -12634,10 +12632,9 @@
} }
}, },
"node_modules/vite": { "node_modules/vite": {
"version": "5.4.10", "version": "5.4.14",
"resolved": "https://registry.npmjs.org/vite/-/vite-5.4.10.tgz", "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.14.tgz",
"integrity": "sha512-1hvaPshuPUtxeQ0hsVH3Mud0ZanOLwVTneA1EgbAM5LhaZEqyPWGRQ7BtaMvUrTDeEaC8pxtj6a6jku3x4z6SQ==", "integrity": "sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==",
"license": "MIT",
"dependencies": { "dependencies": {
"esbuild": "^0.21.3", "esbuild": "^0.21.3",
"postcss": "^8.4.43", "postcss": "^8.4.43",

View file

@ -35,7 +35,7 @@ export default function textType({ text }: TextTypeOptions) {
case 'moodle': case 'moodle':
case 'plain': case 'plain':
// Replace newlines with <br> tags // Replace newlines with <br> tags
return formatText.replace(/(?:\r\n|\r|\n)/g, '<br>'); return replaceNewlinesOutsideSVG(formatText);
case 'html': case 'html':
// Strip outer paragraph tags (not a great approach with regex) // Strip outer paragraph tags (not a great approach with regex)
return formatText.replace(/(^<p>)(.*?)(<\/p>)$/gm, '$2'); return formatText.replace(/(^<p>)(.*?)(<\/p>)$/gm, '$2');
@ -46,3 +46,25 @@ export default function textType({ text }: TextTypeOptions) {
throw new Error(`Unsupported text format: ${text.format}`); throw new Error(`Unsupported text format: ${text.format}`);
} }
} }
// Function to replace \n outside of SVG paths
function replaceNewlinesOutsideSVG(text: string): string {
const svgPathRegex = /<path[^>]*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 <br>
result += text.slice(lastIndex, offset).replace(/(?:\r\n|\r|\n)/g, '<br>');
// 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 <br>
result += text.slice(lastIndex).replace(/(?:\r\n|\r|\n)/g, '<br>');
return result;
}

28
package-lock.json generated
View file

@ -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"
}
}
}
}

View file

@ -1,5 +0,0 @@
{
"dependencies": {
"dompurify": "^3.2.3"
}
}