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(/&amp;/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(); } } }); }
Display clean javascript code for copying
$(document).ready(function(){
// Initialise highlighting
if($('pre').length){
$('pre').each(function(){
highLight($(this));
});
}
});
// Highlight item
function highLight(thisItem){
snippet = thisItem.html();
snippet = snippet.replace(/&amp;/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();
}
}
});
}