$(function(){ $('code').each(function(){ $(this).html(highlight($(this).text())); }); }); function highlight(js) { return js .replace(//g, '>') .replace(/('.*?')/gm, '$1') .replace(/(\d+\.\d+)/gm, '$1') .replace(/(\d+)/gm, '$1') .replace(/\bnew *(\w+)/gm, 'new $1') .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '$1') }