After much googling around, I found two popular ways to add syntax highlighting into Tumblr:
I tried the Syntax Highlighter at first and spent a really long time trying to get it to work. When it finally did, it slowed the loading time by a huge amount, so I switched to the Prettify.
Prettify was a lot simplier to install. The code below automatically adds the prettyprint class to any <code> tag. Alternatively, you can leave out the script and add the class manually.
<!-- For Syntax Highlighting -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css"></link>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js"></script>
<script>
function styleCode() {
if (typeof disableStyleCode != 'undefined') { return; }
var a = false;
$('code').each(function() {
if (!$(this).hasClass('prettyprint')) {
$(this).addClass('prettyprint');
a = true;
}
});
if (a) { prettyPrint(); }
}
$(function() {styleCode();});
</script>
This assumes you don’t already have jQuery.
When posting code, use a text editor to change all the angle brackets to < and > and enclose it in <pre><code></code></pre> tags. The <pre></pre> is necessary to keep the formatting.
Note: The highlighting won’t show up in RSS feeds or the dashboard.
-
ximili reblogged this from snippets-of-code
-
ximili likes this
-
csjoshi04 reblogged this from snippets-of-code
-
csjoshi04 likes this
-
maxleonov likes this
-
4minute4nias likes this
-
jerred likes this
-
albertvp likes this
-
ridinginrails likes this
-
drupality likes this
-
wobblyrobotears likes this
-
wobblyrobotears reblogged this from snippets-of-code
-
tumadman likes this
-
paulodiovani reblogged this from snippets-of-code and added:
Uma das primeiras coisas que fui procurar quando comecei a postar no Tumblr foi um plugin ou script para adicionar...
-
arjunbajaj likes this
-
paulodiovani likes this
-
matossilva likes this
-
warlorderol likes this
-
start-up-tutorials likes this
-
nutrang likes this
-
chichicomvn likes this
-
guinee-conakry-tourisme reblogged this from snippets-of-code
-
xvcvx likes this
-
aradianofftester reblogged this from snippets-of-code
-
aradianoff likes this
-
travisspencer likes this
-
andreasleicher reblogged this from snippets-of-code and added:
Nice way to add syntax highlighting to code in tumblr:
-
cpowrox likes this
-
ironman30 likes this
-
jcgaal likes this
-
sdlog likes this
-
dgk-su likes this
-
nocommenz likes this
-
jwilf reblogged this from snippets-of-code
-
prismalstudio likes this
-
andrewheins likes this
-
pevzi-various likes this
-
abstractfactory likes this
-
pezcuckow reblogged this from snippets-of-code and added:
It’s surprisingly easy...your blog (or any website): Google has
-
tecnoze likes this
-
re-factor likes this
-
tumblrtribune likes this
-
leonh likes this
-
evolutiondesign reblogged this from snippets-of-code and added:
Think I’ll need...this for some of my posts….
-
chrixian likes this
-
mystcolor likes this
-
m-akaveli likes this
-
coeushuizi likes this
-
-random- likes this
- Show more notes