💄 Linkify links in descriptions and comments
This commit is contained in:
parent
c7686d9c84
commit
032ee8ed11
17
src/src/app/shared/linkify.pipe.ts
Normal file
17
src/src/app/shared/linkify.pipe.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user