JSFiddle - React, Tailwind, and code Playground
HTML
<p>HTML HTMLXYZ é muito usado nos dias de hoje, juntamente com o $HTML$ usamos JavaScript e CSS...</p>
JavaScript
$.fn.wrapInTag = function(opts) {
var tag = opts.tag || 'strong',
words = opts.words || [],
regex = RegExp('(\\W|^)(' + words.join('|') + ')(\\W|$)', 'gi'),
replacement = '$1<' + tag + '>$2</' + tag + '>$3';
console.log(regex);
return this.html(function() {
return $(this).text().replace(regex, replacement);
});
};
$('p').wrapInTag({
tag: 'em',
words: ['html', 'CSS', 'JavaScript'],
});