Generating HTML link using DOM manipulation rather that string manipulation

This commit is contained in:
David Négrier 2021-06-04 10:07:12 +02:00
parent eec15b38bb
commit b7ac3b8fad
2 changed files with 11 additions and 2 deletions

View File

@ -381,7 +381,7 @@ body {
max-height: 25%; max-height: 25%;
} }
} }
#game { #game {
@ -1115,6 +1115,10 @@ div.modal-report-user{
color: white; color: white;
} }
.discussion .messages .message p a:visited{
color: white;
}
.discussion .send-message{ .discussion .send-message{
position: absolute; position: absolute;
bottom: 45px; bottom: 45px;

View File

@ -35,7 +35,12 @@ export class HtmlUtils {
const urlRegex = /(https?:\/\/[^\s]+)/g; const urlRegex = /(https?:\/\/[^\s]+)/g;
text = HtmlUtils.escapeHtml(text); text = HtmlUtils.escapeHtml(text);
return text.replace(urlRegex, (url: string) => { return text.replace(urlRegex, (url: string) => {
return '<a href="' + url + '" target="_blank" style=":visited {color: white}">' + url + '</a>'; const link = document.createElement('a');
link.href = url;
link.target = "_blank";
const text = document.createTextNode(url);
link.appendChild(text);
return link.outerHTML;
}); });
} }