replace-urls.ts 507 B

123456789101112131415161718192021222324
  1. import { Pipe, PipeTransform } from "@angular/core";
  2. @Pipe({
  3. name: "replaceUrls"
  4. })
  5. export class ReplaceUrlsPipe implements PipeTransform {
  6. /**
  7. * Takes a string and replaces the urls with hyperlinks.
  8. */
  9. transform(value: string, ...args) {
  10. for (let url of args[0]) {
  11. value = value.replace(
  12. url["url"],
  13. '<a href="' +
  14. url["expanded_url"] +
  15. '" target="_blank">' +
  16. url["display_url"] +
  17. "</a>"
  18. );
  19. }
  20. return value;
  21. }
  22. }