packages/renderer/stringUtils.js
// The function surrounds the keywords wherever they are, even within other words.
The function surrounds the keywords wherever they are, even within other words.
The function surrounds the keywords wherever they are even within other words .
function surroundKeywords(keywords, text, prefix, suffix, options = null) {
	options = Object.assign({}, {
		escapeHtml: false,
	}, options);
	if (!keywords.length) return text;
	function escapeHtml(s) {
		if (!options.escapeHtml) return s;
		return htmlentities(s);
	}
	let regexString = keywords
		.map(k => {
			if (k.type === 'regex') {
				return escapeHtml(replaceRegexDiacritics(k.valueRegex));
			} else {
				const value = typeof k === 'string' ? k : k.value;
				return escapeHtml(replaceRegexDiacritics(pregQuote(value)));
			}
		})
		.join('|');
	regexString = `(${regexString})`;
	const re = new RegExp(regexString, 'gi');
	return text.replace(re, `${prefix}$1${suffix}`);
}
function surroundKeywords ( keywords , text , prefix , suffix , options = null ) { options = Object . assign ( { } , { escapeHtml : false , } , options ) ; if ( ! keywords . length ) return text ; function escapeHtml ( s ) { if ( ! options . escapeHtml ) return s ; return htmlentities ( s ) ; } let regexString = keywords . map ( k => { if ( k . type === 'regex' ) { return escapeHtml ( replaceRegexDiacritics ( k . valueRegex ) ) ; } else { const value = typeof k === 'string' ? k : k . value ; return escapeHtml ( replaceRegexDiacritics ( pregQuote ( value ) ) ) ; } } ) . join ( '|' ) ; regexString = ` ${ regexString } ` ; const re = new RegExp ( regexString , 'gi' ) ; return text . replace ( re , ` ${ prefix } ${ suffix } ` ) ; }
The function surrounds the keywords wherever they are, even within other words.
The function surrounds the keywords wherever they are even within other words .