The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/packages/rocketchat-highlight-words/client/client.js

29 lines
966 B

/*
* Hilights is a named function that will process Highlights
* @param {Object} message - The message object
*/
function HighlightWordsClient(message) {
let msg = message;
if (!_.isString(message)) {
if (_.trim(message.html)) {
msg = message.html;
} else {
return message;
}
}
const to_highlight = Meteor.user() && Meteor.user().settings && Meteor.user().settings.preferences && Meteor.user().settings.preferences.highlights;
if (Array.isArray(to_highlight)) {
to_highlight.forEach((highlight) => {
if (!_.isBlank(highlight)) {
return msg = msg.replace(new RegExp(`(^|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(${ s.escapeRegExp(highlight) })($|\\b|[\\s\\n\\r\\t.,،'\\\"\\+!?:-])(?![^<]*>|[^<>]*<\\/)`, 'gmi'), '$1<span class="highlight-text">$2</span>$3');
}
});
}
message.html = msg;
return message;
}
RocketChat.callbacks.add('renderMessage', HighlightWordsClient, RocketChat.callbacks.priority.MEDIUM + 1, 'highlight-words');