From 9889f3fa96abb4148c7171be5ff8f4d7a1ebfef8 Mon Sep 17 00:00:00 2001
From: Predrag <>
Date: Thu, 25 Jan 2024 09:03:25 +0100
Subject: [PATCH] fix(): not highlighting html tags
---
packages/pipes/src/balHighlight.spec.ts | 10 ++++++++++
packages/pipes/src/balHighlight.ts | 4 ++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/packages/pipes/src/balHighlight.spec.ts b/packages/pipes/src/balHighlight.spec.ts
index 397216f..81acfee 100755
--- a/packages/pipes/src/balHighlight.spec.ts
+++ b/packages/pipes/src/balHighlight.spec.ts
@@ -18,4 +18,14 @@ describe('balHighlight', () => {
`Vertrag`,
)
})
+ test('should return the same text without highlighting when searching <', () => {
+ expect(balHighlight(`Vertrag`, '<')).toBe(
+ `Vertrag`,
+ )
+ })
+ test('should return the same text without highlighting when searching html props', () => {
+ expect(balHighlight(`Vertrag`, 'font-weight')).toBe(
+ `Vertrag`,
+ )
+ })
})
diff --git a/packages/pipes/src/balHighlight.ts b/packages/pipes/src/balHighlight.ts
index 92069e0..e2ddd46 100755
--- a/packages/pipes/src/balHighlight.ts
+++ b/packages/pipes/src/balHighlight.ts
@@ -7,7 +7,7 @@
*/
export function balHighlight(value: string, search: string, cssClass = 'bal-highlight'): string {
if (search && value) {
- const hrefTag = '(href="[^>]+")|('
+ const hrefTag = '(<(.*?)>)|('
let pattern = hrefTag.concat(search.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&')).concat(')')
pattern = pattern
.split(' ')
@@ -17,7 +17,7 @@ export function balHighlight(value: string, search: string, cssClass = 'bal-high
.join('|')
const regex = new RegExp(pattern, 'gi')
return value.replace(regex, match => {
- return match.includes('href') ? match : `${match}`
+ return match.includes('<') && match.includes('>') ? match : `${match}`
})
} else {
return value