$(function(){ /* build and append preformated code examples */ $("div#content").find("p").last().after(buildCodeBlocks); /* toggle/collapse preformated code blocks */ $("pre").bind("click", function(){ this.className = this.className.indexOf("collapse") === -1 ? ( "collapse " + this.className ) : this.className.replace("collapse ", ""); }); /* apply code highlight */ $('pre code').each( function(i, e) { hljs.highlightBlock(e, ' '); }); }); function buildCodeBlocks() { return "
" + "
" + getHtml() + "
" + "
" + cleanJson( $("head script").last().text() ) + "
" + "
" + cleanCSS( $("head style").text() ) + "
" + "
"; } function getHtml() { var clone, ul, li, code; clone = $("
").append($("div#content").contents().not("h2, p").clone()); ul = clone.find("ul"); li = ul.find("li"); li.slice(3, li.length).remove(); ul.append("..."); code = clone.html(); return cleanHTML(code).replace(//gi, ">");; //code = $.tabifier(code, "HTML").replace(//gi, ">"); }