mirror of
https://github.com/driftywinds/driftywinds.github.io.git
synced 2025-12-19 19:13:33 +00:00
Improve URL formatting
This commit is contained in:
14
js/shared.js
14
js/shared.js
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user