1
0
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:
Laurent Cozic
2018-12-29 18:24:02 +01:00
parent 5a00214fd2
commit f308fe71f9
4 changed files with 63 additions and 20 deletions

View File

@ -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 };