2017-08-22 10:53:26 +03:00
|
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
import {htmlSafe} from '@ember/string';
|
2016-06-11 19:52:36 +03:00
|
|
|
|
2016-04-19 18:55:10 +03:00
|
|
|
export function highlightedText([text, termToHighlight]) {
|
2017-09-28 13:25:13 +03:00
|
|
|
// replace any non-word character with an escaped character
|
|
|
|
let sanitisedTerm = termToHighlight.replace(new RegExp(/\W/ig), '\\$&');
|
|
|
|
|
|
|
|
return htmlSafe(text.replace(new RegExp(sanitisedTerm, 'ig'), '<span class="highlight">$&</span>'));
|
2016-04-19 18:55:10 +03:00
|
|
|
}
|
|
|
|
|
2016-06-30 13:21:47 +03:00
|
|
|
export default helper(highlightedText);
|