framework/js/lib/helpers/highlight.js

14 lines
260 B
JavaScript
Raw Normal View History

2015-06-03 16:40:56 +08:00
export default function(string, regexp) {
if (!regexp) {
return string;
}
if (!(regexp instanceof RegExp)) {
regexp = new RegExp(regexp, 'gi');
}
return m.trust(
$('<div/>').text(string).html().replace(regexp, '<mark>$&</mark>')
);
}