Skip to content

Instantly share code, notes, and snippets.

@hyeonseok
Last active Dec 26, 2015
Embed
What would you like to do?
function emphasisKeyword(keyword, string) {
var h = { e: "[eéê]", a: "[aáâ]" };
var matched = keyword.match(/[\S\s]/g);
var res = [];
for (var i = 0; i < matched.length; i++) {
if (h[matched[i]]) {
res.push(h[matched[i]]);
} else {
res.push(matched[i]);
}
};
var re = new RegExp('(' + res.join('') + ')', 'ig');
return string.replace(re, "<strong>$1</strong>");
}
def emphasis_keyword(str, keyword)
h = { "e" => "[eéê]", "a" => "[aáâ]" }
regex = keyword.gsub(/./) {|s| h.fetch(s, s)}
return str.gsub(/(#{regex})/i, '<strong>\1</strong>').html_safe
end
@jeremyBentham

This comment has been minimized.

Copy link

@jeremyBentham jeremyBentham commented Oct 30, 2013

1

@elegantcoder

This comment has been minimized.

Copy link

@elegantcoder elegantcoder commented Oct 30, 2013

2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment