import { Pipe, PipeTransform } from '@angular/core';
import {DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl} from '@angular/platform-browser';

/**
 * Generated class for the ParserPipe pipe.
 *
 * See https://angular.io/docs/ts/latest/guide/pipes.html for more info on
 * Angular Pipes.
 */
@Pipe({
  name: 'parser',
})
export class ParserPipe implements PipeTransform {

  constructor(protected _sanitizer: DomSanitizer) {}

  transform(value: string, ...args): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
    let hregex = /href="([\S]+)"/g;
    // value = value.replace(hregex, "class=\"ex-link\" href=");
    value = value.replace(hregex, "onClick=\"window.open('$1', '_system', 'location=yes')\"");
    return this._sanitizer.bypassSecurityTrustHtml(value);
  }
}
