mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-24 05:05:20 -04:00
(search) use lookarounds to simulate word boundary which works for non-latin scripts
This commit is contained in:
parent
3034fbe209
commit
6a576b6c7a
@ -105,7 +105,9 @@ const getTermsByField = (matches: MatchInfo): Record<string, string[]> => {
|
||||
const FRAGMENT_MAX_WORDCOUNT = 24;
|
||||
|
||||
const highlightMatches = (field: string, terms: string[] | undefined, fragment: boolean = false): string => {
|
||||
const termsRegex = terms && terms.length > 0 ? new RegExp(`\\b(${terms.join('|')})\\b`, 'ig') : undefined;
|
||||
const termsRegex = terms && terms.length > 0
|
||||
? new RegExp(`(?<!\\p{L}|\\p{N})(${terms.join('|')})(?!\\p{L}|\\p{N})`, 'iug')
|
||||
: undefined;
|
||||
|
||||
if (fragment) {
|
||||
const words = field.split(' ');
|
||||
|
Loading…
x
Reference in New Issue
Block a user