17 lines
566 B
JavaScript
17 lines
566 B
JavaScript
|
|
||
|
$(function(){
|
||
|
$('code').each(function(){
|
||
|
$(this).html(highlight($(this).text()));
|
||
|
});
|
||
|
});
|
||
|
|
||
|
function highlight(js) {
|
||
|
return js
|
||
|
.replace(/</g, '<')
|
||
|
.replace(/>/g, '>')
|
||
|
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
||
|
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
||
|
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
||
|
.replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
|
||
|
.replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
|
||
|
}
|