replace-urls.ts 576 B

12345678910111213141516171819202122
  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(url["url"], '<a href="' + url["expanded_url"] + '" target="_blank">' + url["display_url"] + '</a>');
  17. }
  18. return value;
  19. }
  20. }