mirror of
https://github.com/flarum/framework.git
synced 2025-05-21 22:36:01 +08:00
Implement search on front end
This commit is contained in:
13
js/lib/helpers/highlight.js
Normal file
13
js/lib/helpers/highlight.js
Normal file
@ -0,0 +1,13 @@
|
||||
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>')
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user