Compare commits

...

3 commits

Author SHA1 Message Date
C. Fuhrman
d8b1134756 Merge branch 'main' into gift-pegjs-2.0 2025-01-28 15:28:45 -05:00
Christopher (Cris) Fuhrman
cd96cad26d
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
2025-01-28 09:39:09 -05:00
C. Fuhrman
29fd478523 Fixes #201
Copilot GPT 4o a suggéré la nouvelle fonction pour remplacer les `\n` seulement en dehors des PATH svg.
2025-01-27 13:14:50 -05:00

View file

@ -35,7 +35,7 @@ export function FormattedTextTemplate(formattedText: TextFormat): string {
case 'moodle': case 'moodle':
case 'plain': case 'plain':
// Replace newlines with <br> tags // Replace newlines with <br> tags
result = formatText.replace(/(?:\r\n|\r|\n)/g, '<br>'); result = replaceNewlinesOutsideSVG(formatText);
break; break;
case 'html': case 'html':
// Strip outer paragraph tags (not a great approach with regex) // Strip outer paragraph tags (not a great approach with regex)
@ -50,3 +50,25 @@ export function FormattedTextTemplate(formattedText: TextFormat): string {
} }
return DOMPurify.sanitize(result); return DOMPurify.sanitize(result);
} }
// 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;
}