mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
No commits in common. "d8b1134756c1871d93e7d8c4a110a817616ee149" and "842c5956c2ee91ab173f7ac9fea9d7d8007ff621" have entirely different histories.
d8b1134756
...
842c5956c2
1 changed files with 1 additions and 23 deletions
|
|
@ -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 = replaceNewlinesOutsideSVG(formatText);
|
result = formatText.replace(/(?:\r\n|\r|\n)/g, '<br>');
|
||||||
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,25 +50,3 @@ 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;
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue