Skip to content

Commit

Permalink
Merge pull request #52 from Emmenemoi/master
Browse files Browse the repository at this point in the history
modify regex to accept stric words option
  • Loading branch information
mistic100 committed May 6, 2015
2 parents fd490c1 + 01ee330 commit 34c04f3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jquery.highlighttextarea.js
Expand Up @@ -53,6 +53,7 @@
ranges: {},
color: '#ffff00',
caseSensitive: true,
wordsOnly: false,
resizable: false,
id: '',
debug: false
Expand All @@ -66,10 +67,14 @@
Highlighter.prototype.highlight = function() {
var text = Utilities.htmlEntities(this.$el.val()),
that = this;

that.spacer = '';
if (this.settings.wordsOnly ) {
that.spacer = '\\b';
}

$.each(this.settings.words, function(color, words) {
text = text.replace(
new RegExp('('+ words.join('|') +')', that.regParam),
new RegExp(that.spacer+'('+ words.join('|') +')'+that.spacer, that.regParam),
'<mark style="background-color:'+ color +';">$1</mark>'
);
});
Expand Down

0 comments on commit 34c04f3

Please sign in to comment.