import { Pipe , PipeTransform } from '@angular/core' ; import { escapeRegexp } from './common' ; @ Pipe ( { name : 'highlight' } ) export class HighlightPipe implements PipeTransform { public transform ( value , query ) { if ( query . length < 1 ) { return value ; } if ( query ) { let tagRE = new RegExp ( '<[^<>]*>' , 'ig' ) ; let tagList = value . match ( tagRE ) ; let tmpValue = value . replace ( tagRE , '$!$' ) ; value = tmpValue . replace ( new RegExp ( escapeRegexp ( query ) , 'gi' ) , '<strong>$&</strong>' ) ; for ( let i = 0 ; value . indexOf ( '$!$' ) > - 1 ; i ++ ) { value = value . replace ( '$!$' , tagList [ i ] ) ; } } return value ; } } export function stripTags ( input ) { let tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi ; let commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi ; return input . replace ( commentsAndPhpTags , '' ) . replace ( tags , '' ) ; }