Merge pull request #726 from thecodingmachine/fixHtmlAnchorElement

Update to use Anchor type
This commit is contained in:
David Négrier 2021-02-11 18:08:52 +01:00 committed by GitHub
commit 64cd07cc39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -24,11 +24,19 @@ export class HtmlUtils {
throw new Error("Cannot find HTML element with id '"+id+"'");
}
private static escapeHtml(html: string): string {
const text = document.createTextNode(html);
const p = document.createElement('p');
p.appendChild(text);
return p.innerHTML;
}
public static urlify(text: string): string {
const urlRegex = /(https?:\/\/[^\s]+)/g;
text = HtmlUtils.escapeHtml(text);
return text.replace(urlRegex, (url: string) => {
return '<a href="' + url + '" target="_blank" style=":visited {color: white}">' + url + '</a>';
})
});
}
private static isHtmlElement<T extends HTMLElement>(elem: HTMLElement | null): elem is T {