You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Desktop: Improve search keyword highlighting
This commit is contained in:
55
ReactNativeClient/lib/string-utils-common.js
Normal file
55
ReactNativeClient/lib/string-utils-common.js
Normal file
@ -0,0 +1,55 @@
|
||||
function pregQuote(str, delimiter = '') {
|
||||
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
|
||||
}
|
||||
|
||||
function replaceRegexDiacritics(regexString) {
|
||||
if (!regexString) return '';
|
||||
|
||||
const diacriticReplacements = {
|
||||
'a': '[aàáâãäåāą]',
|
||||
'A': '[AÀÁÂÃÄÅĀĄ]',
|
||||
'c': '[cçćč]',
|
||||
'C': '[CÇĆČ]',
|
||||
'd': '[dđď]',
|
||||
'D': '[DĐĎ]',
|
||||
'e': '[eèéêëěēę]',
|
||||
'E': '[EÈÉÊËĚĒĘ]',
|
||||
'i': '[iìíîïī]',
|
||||
'I': '[IÌÍÎÏĪ]',
|
||||
'l': '[lł]',
|
||||
'L': '[LŁ]',
|
||||
'n': '[nñňń]',
|
||||
'N': '[NÑŇŃ]',
|
||||
'o': '[oòóôõöøō]',
|
||||
'O': '[OÒÓÔÕÖØŌ]',
|
||||
'r': '[rř]',
|
||||
'R': '[RŘ]',
|
||||
's': '[sšś]',
|
||||
'S': '[SŠŚ]',
|
||||
't': '[tť]',
|
||||
'T': '[TŤ]',
|
||||
'u': '[uùúûüůū]',
|
||||
'U': '[UÙÚÛÜŮŪ]',
|
||||
'y': '[yÿý]',
|
||||
'Y': '[YŸÝ]',
|
||||
'z': '[zžżź]',
|
||||
'Z': '[ZŽŻŹ]',
|
||||
};
|
||||
|
||||
let output = '';
|
||||
for (let i = 0; i < regexString.length; i++) {
|
||||
let c = regexString[i];
|
||||
const r = diacriticReplacements[c];
|
||||
if (r) {
|
||||
output += r;
|
||||
} else {
|
||||
output += c;
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = { pregQuote, replaceRegexDiacritics };
|
||||
}
|
Reference in New Issue
Block a user