@pocketprep/ui-kit 3.4.78 → 3.4.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@pocketprep/ui-kit.js +1641 -1639
- package/dist/@pocketprep/ui-kit.js.map +1 -1
- package/dist/@pocketprep/ui-kit.umd.cjs +5 -5
- package/dist/@pocketprep/ui-kit.umd.cjs.map +1 -1
- package/lib/pocketprep-export.module.scss +1 -0
- package/lib/styles/_colors.scss +1 -0
- package/lib/utils.ts +6 -2
- package/package.json +1 -1
package/lib/styles/_colors.scss
CHANGED
package/lib/utils.ts
CHANGED
|
@@ -66,6 +66,10 @@ export const studyModes = {
|
|
|
66
66
|
},
|
|
67
67
|
} as const
|
|
68
68
|
|
|
69
|
+
export const escapeRegex = (string: string) => {
|
|
70
|
+
return string.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&')
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
export const highlightKeywordsInText = (params: {
|
|
70
74
|
text: string
|
|
71
75
|
keywordDefinitions: { keyword: string }[]
|
|
@@ -79,7 +83,7 @@ export const highlightKeywordsInText = (params: {
|
|
|
79
83
|
const keywords = params.keywordDefinitions.map(k => k.keyword)
|
|
80
84
|
|
|
81
85
|
return keywords.reduce((acc, word) => {
|
|
82
|
-
const regex = new RegExp(`(\\W)(${word})(\\W)`, 'i')
|
|
86
|
+
const regex = new RegExp(`(\\W)(${escapeRegex(word)})(\\W)`, 'i')
|
|
83
87
|
return acc.replace(
|
|
84
88
|
regex,
|
|
85
89
|
`$1<span class="keyword-highlight${params.isDarkMode
|
|
@@ -89,4 +93,4 @@ export const highlightKeywordsInText = (params: {
|
|
|
89
93
|
<span style="pointer-events: none;">$2</span></span>$3`
|
|
90
94
|
)
|
|
91
95
|
}, params.text)
|
|
92
|
-
}
|
|
96
|
+
}
|