diff --git a/src/src/app/shared/linkify.pipe.ts b/src/src/app/shared/linkify.pipe.ts new file mode 100644 index 0000000..66d5452 --- /dev/null +++ b/src/src/app/shared/linkify.pipe.ts @@ -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 `${url}`; + }); + return this.sanitizer.bypassSecurityTrustHtml(html); + } +}