Skip to content

Instantly share code, notes, and snippets.

@hyeonseok
Last active December 26, 2015 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hyeonseok/7228816 to your computer and use it in GitHub Desktop.
Save hyeonseok/7228816 to your computer and use it in GitHub Desktop.
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
Copy link

1

@elegantcoder
Copy link

2

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