Pretty, ain't it?Usually, Bloggers that post programming codes would want to add this one to their blogs, as it makes everything easier and tidy. You can still use this add-on to post normal texts, if you want your text to stand out from the rest of your contents. There are lots and lots of tutorials out there that teach you how to add it to Blogger. When I first added it, I tried some of these tutorials myself, and not all of them work. So, here's how I added it.
Step 1:
You can skip this step if you're not gonna use SyntaxHighlighter that often.
If you're using the old Blogger interface: Go to Dashboard - Settings - Formatting - Post Template -
If you're using the new Blogger interface: Go to Dashboard - Settings - Posts and comments - Post Template -
Paste the following code - Save Settings:
You can skip this step if you're not gonna use SyntaxHighlighter that often.
If you're using the old Blogger interface: Go to Dashboard - Settings - Formatting - Post Template -
If you're using the new Blogger interface: Go to Dashboard - Settings - Posts and comments - Post Template -
Paste the following code - Save Settings:
<pre class="brush:xml;"> Your code/content goes here. </pre>
Step 2:
If you're using the old Blogger interface: Go to Dashboard - Design - Edit HTML - Back Up (Download Full Template) -
If you're using the new Blogger interface: Go to Dashboard - Template - Backup/Restore - Download Full Template - Close - Edit HTML - Proceed -
Find for </body> - paste the following code directly above </body>:
If you're using the old Blogger interface: Go to Dashboard - Design - Edit HTML - Back Up (Download Full Template) -
If you're using the new Blogger interface: Go to Dashboard - Template - Backup/Restore - Download Full Template - Close - Edit HTML - Proceed -
Find for </body> - paste the following code directly above </body>:
<!-- SH starts --> <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCoreMDUltra.css' rel='stylesheet' type='text/css'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shLegacy.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushAS3.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushColdFusion.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDiff.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushErlang.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushGroovy.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJavaFX.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPowerShell.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushScala.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/> <script language='javascript'> SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.defaults['auto-links'] = false; SyntaxHighlighter.config.clipboardSwf = 'http://alexgorbatchev.com/pub/sh/current/scripts/clipboard.swf'; SyntaxHighlighter.all(); </script> <!-- SH ends -->Click on Save Template once you're done. As you can see here, I have used the files that are being hosted at the official website. Though at first it might seem like hosting these files at an external site is a good idea, I had to learn the hard way that it is not. I hosted my files at Google Sites previously, back when I was still using the Blogspot domain. It worked fine, until I switched to this custom domain. Things went crazy, and it was hard to find one place that could host all files and still be able to work with blogs with custom domains. So take it from me, use these hosted files instead.
Step 3
Now go to New Post, and when you click on Edit HTML, you'll be able to post into SyntaxHighlighter directly. You can remove this HTML portion if you don't want to use it. If you've skipped Step 1, paste the following code in Edit HTML mode and start adding your highlighted contents.:
Now go to New Post, and when you click on Edit HTML, you'll be able to post into SyntaxHighlighter directly. You can remove this HTML portion if you don't want to use it. If you've skipped Step 1, paste the following code in Edit HTML mode and start adding your highlighted contents.:
<pre class="brush:xml;"> Your code/content goes here. </pre>
Customization:
You can customize the current theme and the brush. Changing the theme will change the default text color, background and other things. Changing the brush (I have used XML brush in the steps above) will highlight different set of codes. There are additional customizations that you might want to check out at Alex Gorbatchev's website. Alex is the creator of this useful gadget.
You can customize the current theme and the brush. Changing the theme will change the default text color, background and other things. Changing the brush (I have used XML brush in the steps above) will highlight different set of codes. There are additional customizations that you might want to check out at Alex Gorbatchev's website. Alex is the creator of this useful gadget.
Themes |
shThemeRDark, shThemeMidnight, shThemeMDUltra, shThemeFadeToGrey, shThemeEmacs, shThemeEclipse, shThemeDjango, shThemeDefault, shCoreRDark, shCoreMidnight, shCoreMDUltra, shCoreFadeToGrey, shCoreEmacs, shCoreEclipse, shCoreDjango, shCoreDefault
Note: I have used shCoreMDUltra in the tutorial above. To change your theme, simply locate the line that contains the word 'shCoreMDUltra', and replace it with one of the theme names above. Retain the .css extension and whatever filepath before it. |
Brushes |
as3, bash, csharp, coldfusion, cpp, css, diff, erlang, groovy, jscript, java, javafx, perl, php, plain, powershell, phython, ruby, scala, sql, vb, xml
Note: to change your brush, while creating a new post, use one of the brushes listed above. In the tutorial above, I have used the xml brush. |
You are the best! I'll be trying this out. Thank you so much for answering this question, especially after you've answered and helped me more than enough.
ReplyDeleteI get so confused with other people's directions. I think I'm just so used to reading and following yours - you make it simple and always break it down.
So, no need to rush on tutorials; We understand you have life aside from teaching and helping us. =D
~Raina
There are currently six girls that can post on the VBoard (The LUV'NV's Admins only blog), and they do not have any HTML experience, so I don't want those tags shown in the HTML of posts. Can I skip Step #1 and still use SH in the static pages?
ReplyDeleteI'm not entirely sure how I show SH on the static pages as well. Do I use the tags in Step #3, and paste those tags where I want it in the Edit HTML tab of pages?
Thanks always, Blog Saint Yoboy. ;)
~Raina
=) Nevermind. I'm slow today, and I just figured it out. =P ~Raina
ReplyDeleteRaindropSoup: No problem at all. If this doesn't work, feel free to let me know, I'll point you at some other sites that use slightly different methods.
ReplyDeleteAll right, it works in posts but not in pages. Is there other tags I could use to put SH on a static page? Other site recommendations are welcome too.
ReplyDeleteThanks, Blog Saint Yoboy!
~Raina
RaindropSoup: SH is a set of scripts. Once you've added it to your site, you should be able to call it from anywhere within your site. If it works with your normal post page, it will work with your static page as well. I have quickly tried this with Pattern Art template (your base template) and it does work in a static page as well.
ReplyDeleteClick here to see a screenshot of this.
Just that you have to insert the correct pre code in Edit HTML mode. Try this, go to a static page, Edit, Edit HTML and just enter this code in Edit HTML:
<pre class="brush:xml;">Your code/content goes here.
</pre>
It should work when you publish it. Could you just quickly try this one? BTW, GreenLava has some of the best tutorials. Check out his tutorial on SH here.
A quick question... how can I get a scroll bar at the bottom of the SH table? Or does that only apply with specific themes?
ReplyDeleteRainsdropsoup: I cant seem to able to word-wrap syntax-highlighter when it is used in a table too. That's sucks, I know. But I'm sure there's a way. I'll ask GreenLava if it's possible.
ReplyDeleteWell, when I use SH on my site, it doesn't have a scroll bar at all.
ReplyDeleteFor example, in Step #2 above, your SH has a horizontal scroll bar at the bottom, because the tags in a line are longer than the actual width. I don't get that at all. It's not a big deal, I just thought that was weird.
I did find a way to add a scroll bar in actual tables here: http://www.htmlbasix.com/scrollingtable.shtml.
I can get tags in tables fine and a scroll bar in a table just fine too. There's just no scroll bar in my SH. Thanks, Yoboy.
RaindropSoup: This code of yours, does it happen to be of a single line? There's a bug in SH, it wont add a scroll bar if it is a single line. Just add another line to it.
ReplyDeleteAh, that was the problem then. =)
ReplyDeleteThanks for clearing that up and for creating this tutorial for me.
~Raina
RaindropSoup: No problem at all. Glad that cleared the air.
ReplyDeleteThis solution worked like anything in the first go.
ReplyDeleteI am happy. Please check my blog:
http://owntechnology.blogspot.com
Sandeep: Looking good. That's as neat as it can be. Regards.
ReplyDeleteCan be very useful for people who post a lot of 'code' in their content (maybe also for those who just want to make their blog more aesthetically pleasing/pretty)
ReplyDeleteGoing to look at this closer later and see how well it works and how easy it is to implement.
Going to 'follow', I look forward to seeing more posts from you.
@Rahim: That's true. Try it out and see how it goes. Things have been a little slow lately as I have just gotten to a new place and I'm still settling down. But I will be back at full swing real soon. Cheers.
ReplyDeleteThanks for the article. This is going to come in handy for my site. I have tutorials that include code examples. I just need to go back to each article and update my pages.
ReplyDeleteHandy indeed. Happy blogging :)
Deletenice share ... helpful for beginners.
ReplyDeleteNo biggie :)
DeleteI have pasted these codes in my template but when i write xml in my post it goes outside the post body area showing little bit of it's left portion
ReplyDeleteGimme a URL so that I can have a look..
DeleteMy blog: http://technotrickology.blogspot.in/
ReplyDeleteActually the xml codes do not appear on the link page,you can see by Clicking on the name "Jayanta"
Looks fine to me. See attached screenshot.
DeleteScreenshot
Your code is highlighting, and you have a horizontal scrollbar to show overflowing lines.. I don't see anything wrong with it..
See this screenshot
Deletehttps://lh6.googleusercontent.com/-xTFPkxAZJAM/UBXmg2fJa2I/AAAAAAAAAX8/vvicRPdxJ4Q/s689/Capture.JPG
when i click on post title it appears like this
click on the blog post titl,the problem occurs on the link page only
ReplyDeleteSeems like a compatibility issue between the highlighter and your template. To mitigate this issue, go to Dashboard - Template - Edit HTML - Find for
Delete</b:skin> - Paste the following directly below
</b:skin>:
<b:if cond='data:blog.pageType == "item"'>
<style>
.syntaxhighlighter{
left: -670px;
}
</style>
</b:if>
Let me know how it goes..
It worked.
DeleteIt has some problem while using in blogger's dynamic views, it will cause the blog theme become the default dynamic views theme (like what your blogger looks like under dynamic views)
ReplyDeleteYeap, you're spot on.. Won't work properly with Dynamic View templates..
DeleteAny tweaks to fix it?
DeleteNone that I can think of.. Sorry..
DeleteHi Yoga, i have installed syntax highlighter working good. But how can i disable vertical scroll bar in the blogger...
ReplyDeleteMight be an entirely different issue. Mind if I take a look at the page you're referring to?
Delete