Jquery geshi
17 Ⅴ 2010
Code highlighting using ajax with jquery and geshi.
$(document).ready(function(){
// Initialise highlighting
if($('pre').length){
$('pre').each(function(){
highLight($(this));
});
}
});
// Highlight item
function highLight(thisItem){
snippet = thisItem.html();
snippet = snippet.replace(/&/ig, escape('&'));
snippet = snippet.replace(/</ig, '<');
snippet = snippet.replace(/>/ig, '>');
language = thisItem.attr('class');
$.ajax({
type: "POST",
url: '/scripts/highlight.php',
data: 'language='+language+'&snippet='+snippet,
dataType: "html",
success: function(msg){
if (msg){
msg = msg.replace('&', '&');
thisItem.after(msg);
thisItem.hide();
}
}
});
}