You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-06-15 23:00:36 +02:00
Mobile: Fixes #1082: Highlight correct keywords when doing a search
This commit is contained in:
@ -224,8 +224,21 @@ function escapeHtml(s) {
|
||||
.replace(/'/g, "'");
|
||||
}
|
||||
|
||||
function pregQuote(str, delimiter) {
|
||||
function pregQuote(str, delimiter = '') {
|
||||
return (str + '').replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]', 'g'), '\\$&');
|
||||
}
|
||||
|
||||
module.exports = { removeDiacritics, escapeFilename, wrap, splitCommandString, padLeft, toTitleCase, escapeHtml, pregQuote };
|
||||
function surroundKeywords(keywords, text, prefix, suffix) {
|
||||
let regexString = keywords.map((k) => {
|
||||
if (k.type === 'regex') {
|
||||
return k.value;
|
||||
} else {
|
||||
return pregQuote(k);
|
||||
}
|
||||
}).join('|');
|
||||
regexString = '\\b(' + regexString + ')\\b'
|
||||
const re = new RegExp(regexString, 'gi');
|
||||
return text.replace(re, prefix + '$1' + suffix);
|
||||
}
|
||||
|
||||
module.exports = { removeDiacritics, escapeFilename, wrap, splitCommandString, padLeft, toTitleCase, escapeHtml, pregQuote, surroundKeywords };
|
Reference in New Issue
Block a user