Last active
February 21, 2016 07:55
-
-
Save sysint64/aa101e84db8b5585dee0 to your computer and use it in GitHub Desktop.
Ucoz code highlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js?autoload=true&lang=css" defer="defer"></script> | |
<script> | |
function resize() { | |
$(".prettyprint").css("width", 700); | |
$(".prettyprint").each(function() { | |
var parent = $(this).closest(".posttdMessage"); | |
$(this).css("width", $(parent).width()-24); // 24 - 2*12 padding | |
}); | |
$(".posttdMessage img").css("max-width", 700); | |
$(".posttdMessage img").each(function() { | |
var parent = $(this).closest(".posttdMessage"); | |
$(this).css("max-width", $(parent).width()); | |
}); | |
} | |
$(window).resize(function() { | |
resize(); | |
}); | |
$(document).ready(function() { | |
var langs = ["bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html", | |
"java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh", | |
"xhtml", "xml", "xsl"]; | |
langs.sort(function(a, b){ | |
return b.length - a.length; // ASC -> a - b; DESC -> b - a | |
}); | |
$(".codeMessage").each(function() { | |
var str = $(this).html(); | |
var obj = $(this); | |
langs.forEach(function(item) { | |
var regex = new RegExp("\-"+item); | |
str = str.replace(regex, "<span class='prettyprint-lang' lang='"+item+"'></span>"); | |
}); | |
$(obj).replaceWith("<pre class=\"prettyprint\">"+str+"<br></pre>"); | |
}); | |
$(".prettyprint").each(function() { | |
var lang = $(this).find(".prettyprint-lang"); | |
if ($(lang).length > 0) { | |
var langVal = $(lang).attr("lang"); | |
$(this).addClass("lang-"+langVal); | |
} | |
}); | |
resize(); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment