/* Code highlighting. Feel free to use, but note it isn't that solid */
jQuery.fn.highlight = function() {
$(this).each(function(){
var elm = $(this);
switch(elm.data('type')){
case 'json':case 'js':
elm.html(elm.text()
.replace(/([^\"]*)([\"][^\"]*[\"])([^\"]*)/gi,'$1$2$3')
.replace(/([^\']*)([\'][^\']*[\'])([^\']*)/gi,'$1$2$3')
.replace(/(function|this|document|for|if|else|var|true|false|throw|return|while|break|typeof|catch|new|undefined|null|class|yield|let|const|switch|break|case|continue|try|delete|in|of)([\s()]+)/g,
'$1$2')
.replace(/(\w+)(?=\.)/gi, '$1')
.replace(/(cite)([(<])/gi, '$1$2')
.replace(/(cite)([^\(<])/gi, '$1$2')
.replace(/(\w+)(\s*\:)/gi,'$1$2')
.replace(/([\s\.{};(])([\w$]+)(?=\s*\()/gi,'$1$2')
.replace(/^(.*)(\/\/.*)$/gim,'$1')
.replace(/(\/\*[\s\S]*?\*\/)/gi,'')
.replace(/(-?(?:\d+\.\d+|\d+\.|\.\d+|\d+)(?:e\d+)?)/gi,'$1')
);
break;
case 'bib':
elm.html(elm.text()
.replace(/(=\s*)(?:("{)(.*?)(}")|(")(.*?)(")|({{)(.*?)(}})|({)(.*?)(})|(.*?))(?=\s*[,}])/g,
function (m,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14) {
p1=p1||'',p2=p2||'',p3=p3||'',p4=p4||'',p5=p5||'',p6=p6||'',p7=p7||'',p8=p8||'',
p9=p9||'',p10=p10||'',p11=p11||'',p12=p12||'',p13=p13||'',p14=p14||'';
var rgx = /^\d+$/, string = (
p3 .match( rgx ) ||
p6 .match( rgx ) ||
p9 .match( rgx ) ||
p12.match( rgx ) ||
p14.match( rgx )
) ?
'digit'
:
'string';
return p1+p2+p5+p8+p11+''+p3+p6+p9+p12+p14+''+p4+p7+p10+p13
})
.replace(/(\@)([^\@\{]+)(\{)(\w+)(\,)/gi,'$1$2$3$4$5')
.replace(/(\w+)\s*(\=)(\s|[^\'\"\w]+)/gi,'$1 $2 ')
);
break;
case 'url':
elm.html(elm.text()
.replace(/(https?:\/\/)?((([a-z\d]([a-z\d-]*[a-z\d])*)\.)+[a-z]{2,}|((\d{1,3}\.){3}\d{1,3}))(\:\d+)?((\/[-a-z\d%_.~+:]*)*)(\?[;&a-z\d%_.~+=-]*)?(\#[-a-z\d_]*)?/gi,
'$1'+
'$2$8'+
'$9$12'+
'$11'
)
)
break;
default:return;break;
}
});
}