replace-urls.ts 639 B

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