Improve URL formatting

This commit is contained in:
foxster-mp4
2023-05-21 16:26:49 -07:00
parent 545025d1a7
commit 9145271393

View File

@@ -101,11 +101,19 @@ function formatString(string) {
// URLs // URLs
const urlArray = string.match(urlRegex); const urlArray = string.match(urlRegex);
const urlSet = [...new Set(urlArray)]; // Converting to set to remove duplicates // const urlSet = [...new Set(urlArray)]; // Converting to set to remove duplicates
urlSet.forEach(url => string = string.replaceAll(url, `<a href="${url}">${url}</a>`)); var result = "";
urlArray.forEach(url => {
string = string.replace(url, `<a href="${url}">${url}</a>`)
// Remove formatted substring so it won't get formatted again (prevents <a> tag within the href attribute another <a> tag)
let endIndexOfClosingTag = string.indexOf("</a>") + 4;
let formattedSubstring = string.substring(0, endIndexOfClosingTag);
result += formattedSubstring;
string = string.replace(formattedSubstring, "");
});
// New lines // New lines
return string.replaceAll("\n", "<br>"); return result.replaceAll("\n", "<br>");;
} }
function setTintColor(color) { function setTintColor(color) {