This is an optional step. You don't necessarily have to download it because you can just link to the free hosted version. But if you have your own server you can download the latest version of SyntaxHighlighter here and upload it. 2. Link to CSS and Javascript
Open your webpage's HTML file and add links to the SyntaxHighlighter's CSS and JavaScript files. For optimal results, place these lines at the very end of your page, just before the closing body tag.
<link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shCore.css"></link> <link type="text/css" rel="stylesheet" href="http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css"></link> <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js"></script> <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shLegacy.js"></script> <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js"></script> <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js"></script> <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js"></script> <script type="text/javascript" src="http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js"></script> <script type="text/javascript"> SyntaxHighlighter.config.bloggerMode = true; SyntaxHighlighter.all(); </script>It is not necessary to add the js files for all the languages - just for the ones you will be using. 3. Add Code
Now add the code you wish to highlight in your webpage, surrounded by the
<pre>
tag. Set the class
attribute to one of the language aliases you wish to use, such as java, xml, sql, ruby etc.For example: brush:java
<pre title="Test SyntaxHighlighter" class="brush: java;"> public void printHello(){ System.out.println("Hello World"); } </pre>4. View Page
View the webpage in your browser and you should see your syntax highlighted code snippet as:
public void printHello(){ System.out.println("Hello World"); }Configuration Options
Here are a couple of handy options. (Full list of here):
- If you don't want to display the line numbers column, use the
gutter
option e.g.gutter:false
. - If you don't want to display the top toolbar, use the
toolbar:false
option.
SyntaxHighlighter Homepage
Great job on this tutorial.
ReplyDeleteHowever I would like to know whether is it possible to post VBA codes on blogger template ??
Please help....
For VB, use:
ReplyDeletename="code" class="vb"
The list of supported languages is here:
http://code.google.com/p/syntaxhighlighter/wiki/Languages
Thanks for that info...
ReplyDeleteI will reply back once done.
AsSalaamAlaikum,
Ilyas Kazi
Jazak Allah!
ReplyDeleteI hv implemented here: http://automax-vba.blogspot.com
Ilyas Kazi
thanx for sharing
ReplyDeleteI just want to know how to remove the code line number when copying the snippet? Seems like the numbering still be added when copying even "nogutter" configuration is set.
I've already test it in my site
ReplyDeleteNice info
Hi Fahd,
ReplyDeleteThanks a lot for putting this together.
I have made the Syntax Highlighter source code files available here:
http://howard.ross.work.googlepages.com/syntaxhighlighting
Good job, Howard!
ReplyDeleteThanks for the write-up. Saved me the effort! You might want to make your example text reflect all the same paths. Your path in the last line of the clipboard points to js/ which is not consistent with the others, or how you use it on your page.
ReplyDeleteI also found I had to change the default setting of blogger to not insert BR for linebreaks in the editor. Under Settings->Formating->Convert Line Breaks set to NO
Do you have problems with the Blogger editor complaining about some of the code posted as well? For instance trying to post the example which had the link for the stylesheet triggers the Editor's code checking. Do you see the same?
Steve,
ReplyDeleteI remember having similar problems, so switched to "Blogger in draft" which has improved raw HTML support. You can set it to ignore newlines instead of converting them to br tags.
More info on blogger in draft here: http://bloggerindraft.blogspot.com/
I have fixed the paths.
ReplyDeleteGood spot!
Fahd,
ReplyDeleteAs Azo asked, do u know how to eliminate row numbers while copying? Even though we set as 'nogutter' the problem still exist.
When all selected and copied it shows row numbers. When some lines selected it shows hash (#).
Could you fix it?
thanks very much. this really helped me to get it working as i am not such an experienced user. now it works just perfect.
ReplyDeleteThanks Fahd. It did me a great favor.
ReplyDeleteBTW, would you mind my translation of this post to Chinese and post on my blog so that your post will then help more people?
Hi chzhcn,
ReplyDeleteI'm glad you found it helpful. Feel free to post a chinese version of this on your blog.
I want to add it in my jsp files. But i am facing path problems as all pages are in different folders. Can you help me in this?
ReplyDeleteYour blog was great help.
ReplyDeleteif you experience issues with "br" in output take a look at this: http://code.google.com/p/syntaxhighlighter/wiki/BloggerMode
hi
ReplyDeleteThanks for ur write ups
And thanks to Jim Shingler also for leading me to solve the
error
Thanks for writing this up. It's much better than the original doc on the main google site.
ReplyDeleteWhat is your settings for 'Convert line breaks' set to? In my case, if I set it to 'Yes', it's inserting <br /> into codes defined under <pre> tag.
ReplyDeleteHi,
ReplyDeleteA while a go I implemented this syntax highlighter as well on my own blog. In internet explorer 7 the loading speed is ok I think, but when loading one of my pages with syntax highlights in firefox, the page loads really slow. It causes the browser to freeze for a while
However your blog loads really fast in a firefox browser.
Would it be possible for you to have a look at one of my pages and tell me what I'm doing wrong? :-)
(for instance: http://www.testingminded.com/2009/04/automatic-pagerank-checking-script.html)
Many thanks!
Nevermind, I found the solution. The autoit brush has a size of 52 kb in comparison with others which only have a size of 4 kb. I commented out the UDF's regexp in the autoit brush.
ReplyDeleteI keep getting a 'dp is undefined' error on the client. shCore is being included ok so what gives?
ReplyDeleteThank you SOOOOOOO much!! I didn't feel like digging around in the code to figure out how to use the damn thing.
ReplyDeleteCan you please give me a java code example to show how to use it properly to post code on blogspot.com.
ReplyDeleteVery helpful, but can you provide more insight as to how to use it for Blogger? You mentioned that we need to use Google Pages but can you elaborate more on that? Thank you very much!
ReplyDeleteThis post is deprecated. Please read my new entry on: "Upgrading to SyntaxHighlighter 2.0"
ReplyDeletehttp://fahdshariff.blogspot.com/2009/09/upgrading-to-syntaxhighlighter-20.html
thanks a lot
ReplyDeleteThanks for it!
ReplyDeleteI have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards
ReplyDeletehi, the latest version of SyntaxHighlighter is very good I like it.
ReplyDeleteThis type of lace wig looks very realistic and is made from sophisticated lace material having the original look. Not just full lace wigs,lace front wigs,full lace wigs gives a natural character but lace wigs and lace front wigs also render a fashionable look to the face. The lace wigs in this wig usually appears as if it is growing out of the scalp and equally distributed. Some manufacturers now are trying to make their lace front human hair wigs inexpensive so that ladies who really need it can afford to buy it.
ReplyDeleteHi I am Hitesh Panchal,
ReplyDeleteI have downloaded "SyntaxHighlighter_1.5.1" and create sample applcation in Dot NET. It works fine in InterNet Explorer but it not works with FireFox. (NO any Error Prompt)
so any one know how can i do this ?
Regards,
Hitesh Panchal
Your blog is really helps for my search and i really like it.. Thanks a lot..:)
ReplyDeleteTerm Papers Writing Services
Thank you. Couldn't get SyntaxHighlighter to work until I found you. Awesome! Thanks.
ReplyDelete