mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 04:13:30 +03:00
12 lines
440 B
JavaScript
12 lines
440 B
JavaScript
import {helper} from '@ember/component/helper';
|
|
import {htmlSafe} from '@ember/template';
|
|
|
|
export function highlightedText([text, termToHighlight]) {
|
|
// 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>'));
|
|
}
|
|
|
|
export default helper(highlightedText);
|