discourse/app/assets/javascripts/discourse/lib/highlight-text.js.es6
Sam 0791d740a6 FIX: only highlight exact word matches in results
- also fixes phrase highlighting
2017-07-20 12:26:46 -04:00

9 lines
341 B
JavaScript

export default function($elem, term) {
if(!_.isEmpty(term)) {
// special case ignore "l" which is used for magic sorting
let words = _.reject(term.match(/"[^"]+"|[^\s]+/g), t => t === 'l');
words = words.map(w => w.replace(/^"(.*)"$/, "$1"));
$elem.highlight(words, {className: 'search-highlight', wordsOnly: true});
}
}