aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/angular/highlight.pipe.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/angular/highlight.pipe.ts')
-rw-r--r--client/src/app/shared/angular/highlight.pipe.ts20
1 files changed, 10 insertions, 10 deletions
diff --git a/client/src/app/shared/angular/highlight.pipe.ts b/client/src/app/shared/angular/highlight.pipe.ts
index fb6042280..50ee5c1bd 100644
--- a/client/src/app/shared/angular/highlight.pipe.ts
+++ b/client/src/app/shared/angular/highlight.pipe.ts
@@ -11,19 +11,17 @@ export class HighlightPipe implements PipeTransform {
11 /* use this for global search */ 11 /* use this for global search */
12 static MULTI_MATCH = 'Multi-Match' 12 static MULTI_MATCH = 'Multi-Match'
13 13
14 // tslint:disable-next-line:no-empty
15 constructor () {}
16
17 transform ( 14 transform (
18 contentString: string = null, 15 contentString: string = null,
19 stringToHighlight: string = null, 16 stringToHighlight: string = null,
20 option = 'Single-And-StartsWith-Match', 17 option = 'Single-And-StartsWith-Match',
21 caseSensitive = false, 18 caseSensitive = false,
22 highlightStyleName = 'search-highlight' 19 highlightStyleName = 'search-highlight'
23 ): SafeHtml { 20 ): SafeHtml {
24 if (stringToHighlight && contentString && option) { 21 if (stringToHighlight && contentString && option) {
25 let regex: any = '' 22 let regex: any = ''
26 const caseFlag: string = !caseSensitive ? 'i' : '' 23 const caseFlag: string = !caseSensitive ? 'i' : ''
24
27 switch (option) { 25 switch (option) {
28 case 'Single-Match': { 26 case 'Single-Match': {
29 regex = new RegExp(stringToHighlight, caseFlag) 27 regex = new RegExp(stringToHighlight, caseFlag)
@@ -42,10 +40,12 @@ export class HighlightPipe implements PipeTransform {
42 regex = new RegExp(stringToHighlight, 'gi') 40 regex = new RegExp(stringToHighlight, 'gi')
43 } 41 }
44 } 42 }
43
45 const replaced = contentString.replace( 44 const replaced = contentString.replace(
46 regex, 45 regex,
47 (match) => `<span class="${highlightStyleName}">${match}</span>` 46 (match) => `<span class="${highlightStyleName}">${match}</span>`
48 ) 47 )
48
49 return replaced 49 return replaced
50 } else { 50 } else {
51 return contentString 51 return contentString