💄 Linkify links in descriptions and comments

This commit is contained in:
itskovacs 2025-08-05 18:15:33 +02:00
parent c7686d9c84
commit 032ee8ed11

View File

@ -0,0 +1,17 @@
import { Pipe, PipeTransform } from "@angular/core";
import { DomSanitizer, SafeHtml } from "@angular/platform-browser";
@Pipe({ name: "linkify", standalone: true })
export class LinkifyPipe implements PipeTransform {
constructor(private sanitizer: DomSanitizer) {}
transform(text: string): SafeHtml {
if (!text) return text;
const urlRegex = /((https?:\/\/|www\.)[^\s]+)/g;
const html = text.replace(urlRegex, (url) => {
return `<a href="${url}" target="_blank">${url}</a>`;
});
return this.sanitizer.bypassSecurityTrustHtml(html);
}
}