Well, that previous post almost drove me nuts! I clicked on the publish button, quickly previwed the post, and then went to bed.
The next day (i.e. yesterday), I was pleasantly checking my post only to see that all the parts that contain code are a mess!
The culprit? It turned out to be the "less than" or "<" symbol. Obviously, the Google WYSIWYG editor, although very smart and easy to use, does not automatically convert the "less than" (and other) symbols into their html equivalent when they are used withing a blockquote for example. Why do we need to convert in the first place? Because html tags start with a "less than" symbol. So the html code was treating the "<" symbol as the opening of an html tag. The first solution to this is to manually enter the html code for "<" in the html editor of the post. The html equivalent for "<" is
<
.The second solution is to wait and hope for the Blogger team to incorporate some features for programmers in the WYSIWYG editor. (thanks Blogger team, by the way).
Finally, after figuring that out, I also wanted to add some syntax highlighting into my code. I found this nice syntax highlighter on google code.
To make this work on blogger, do the following
- Download SyntaxHighlighter here
- Unzip and upload the following files to your webspace (googlepages is a great place)
- SyntaxHighlighter.css
- shCore.js'
- shBrushCpp.js (or whatever code you wish to use on your blog)
- Go to your Dashboard/Layout/Edit HTML
- Add the following code right after the tag
<!-- end outer-wrapper -- ><link href='YOUR_GOOGLE_PAGES/SyntaxHighlighter.css' rel='stylesheet'
type='text/css'/>
<script language='javascript' src='YOUR_GOOGLE_PAGES/shCore.js'/>
<script language='javascript' src='YOUR_GOOGLE_PAGES/shBrushCpp.js'/>
<script language='javascript'>
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll('code');
</script>
Now to add source code to a post, it should be placed in <pre> tag. Obviously, you have to do this within the "Edit Html" tab of the Google editor. The typical format that I use is
voila!<pre name="code" class="Cpp">
...insert code here...
</pre>
Cite as:
Saad, T. "Posting Source Code in Blogger".
Weblog entry from
Please Make A Note.
https://pleasemakeanote.blogspot.com/2008/06/posting-source-code-in-blogger.html?m=0
Thanks for sharing this post. I get it done also for my blog now.
ReplyDeleteI did test the hole method offline on a local copy of a post.
Here are the lines that worked for me:
<link href="http://lockimage.googlepages.com/SyntaxHighlighter.css" rel="stylesheet" type="text/css"/>
<script language="javascript" src="http://lockimage.googlepages.com/shCore.js"></script>
<script language="javascript" src="http://lockimage.googlepages.com/shBrushCpp.js"></script>
<script language="javascript">
dp.SyntaxHighlighter.BloggerMode();
dp.SyntaxHighlighter.HighlightAll("code");
</script>
</body>
</html>
It is very important that the lines come directly before the end of the HTML template.
Cheers, Paco
great find.
ReplyDeleteI have problem with my post comment code in my blog. Do you know what is wrong? http://kristelschneiderphotographyblog.blogspot.com/
ReplyDeleteOr use Windows Live Writer which allows you to do this without having to hack the HTML code. See http://skotl.blogspot.com/2009/02/posting-code-snipped-on-blogspotcom.html for more info, or http://www.webtechdaily.com/2008/10/01/top-10-reasons-to-use-windows-live-writer-for-writing-your-blog-posts/ for 10 good reasons to use WLW.
ReplyDeleteThanks man...
ReplyDeletehttp://java2everyone.blogspot.com
Great post. I have been playing with Ubiquity to make it easy to escape all the right characters and add the <pre> tags. You can get the Ubiquity verb from my blog http://tinyurl.com/ag27dc
ReplyDeleteThank you so much; I used the newer syntaxhighligher 2.0 on my blog http://weicode.blogspot.com/, it looks nice!
ReplyDeletehi, I want to ask how you put your words ( just the steps you told us how to use systaxHighlighter on blogger ) into one frame in your blog. thanks.
ReplyDeleteHi... Great blog and you done a great job. I want to use the syntaxhighligher but i don't know how? But know i can take some help from your post. Hopefully it works.Keep up the good work.
ReplyDeleteyou're great. keep sharing ideas. thanks
ReplyDeleteThank you so much ...
ReplyDeleteExcellent and very fresh article.Visit me at www.techieway.blogspot.com
ReplyDeleteHi, this post saved me lot of time!, thank you! very useful!
ReplyDeletewho know about code blogspot please help me.
ReplyDeletehttp://talentsokker1.blogspot.com/
my blog has failed addon tratu.vn (baamboo) of firefox installed on my, now I wish to go without. My blog is open source code that can add on it but can not find the code in Html edit your blogspot
thanks
thanks for good site and tutorial... if u want something JAVA like
ReplyDeleteImage-thumbnail-viewer-effect..
Please Visit Our site at www.warehack.blogspot.com
Thanks for nice tips. This post helped me to groom my blog http://cherupally.blogspot.com
ReplyDeleteCheck Out The Easy Steps No Need To Upload The Files .
ReplyDeleteJust A small Entrie
Use This Link :
http://bloggerstrade.blogspot.com/2010/03/how-to-display-html-code-in-blogger.html
Thanks.
ReplyDeleteyour provided article helped me a lot.
I dont have words to thank you.
ReplyDeleteThanks. Great work !!!!!!!!!
ReplyDeletethx
ReplyDeletehttps://www.tsmguide.co.cc
Thanks for posting the source code for syntax highlighter!!
ReplyDeleteReally like this website, this really helps and very useful.I really like flowers and also interested to send flowers all over the world.......
ReplyDeletegrrr8 info thanks
ReplyDeleteI love your blog. Thanks for sharing with us your arzticles
ReplyDeleteHi... Great blog and you done a great job. I want to use the syntaxhighligher but i don't know how? But know i can take some help from your post. Hopefully it works.Keep up the good work.
ReplyDeleteBlogger source code is highly complex and you need coding experience to customize it. On the other hand wordpress is really helpful
ReplyDeleteWow, am so lucky to have found this, thanks for the help.
ReplyDeleteI'll definitely try this one out. Thanks
ReplyDeleteThis is a great post. Alternatively, feel free to try codexplode.com to be able to format and post your code easily into your blogger blog. It is a free service.
ReplyDeleteI just writing to say that you have posted some interesting posts recently and I was quite exited to find your blog and read all your articles
ReplyDeleteHari Sha, thank you!!!!!
ReplyDeleteThank you so much; I used the newer syntaxhighligher 2.0 on my blog it looks nice!
ReplyDeleteit`s eazy when u use wordpress :(
ReplyDeletebut you can use blockquote to do this right? but it wont highlight i guesss
ReplyDeleteThe world can be changed by man's endeavor, and that this endeavor can lead to something new and better .
ReplyDeleteHow would i upload a Povray file onto a blog..and show the source code?!?!?
ReplyDeleteDo you have any other info about changing the blogger code? Im struggling and I think I will use wordpress istead
ReplyDeletedoes not work :(
ReplyDeletesee my blogs and 6 million jobs http://ainaow.jobamatic.com
ReplyDeletehttp://ainaow.blogspot.com
After a little tweaking a playing around finally made it work! Thanks for this post, was finally able to clean up all that mess.
ReplyDeleteThis works for me fine,
ReplyDeletealso thanks for lockimage :)
Hi Guys catch all the program codes that you need during your Engineering in this Blog.... All the Programs related to C,C++,Java, Simulation and Modelling are available... They are written as simple as possible.... Catch these codes on
ReplyDeletewww.ezeecodes.blogspot.com
sclerotherapy, sclerotherapy training, sclerotherapy course, sclerotherapy certification, varicose vein training.
ReplyDeletegoogle prettify can do such thing simpler,lighter,and even better than your syntax highlighter.
ReplyDeleteRegards
kevin-yonathan.blogspot.com
All about my minds,experience and life
u can use a simple online app, TOHTML
ReplyDeletehere u can enter the source code , select the language and style and get html code ,that u can paste in the editor to get a formatted code, i have used it and it also highlights different syntax.. check a post for demo a post for demo here
Hi Tony,
ReplyDeleteI implented your solution in my Blogger (gruis.blogspot.com), but inthe browser Internet Explorer (I use version 8) the code is generated, and not shown.
Is this problem (and the solution) known by you?
Thanks,
Hans Drieman
Excellent information. I am proud of you. Because you collect most important information.
ReplyDeleteThanks
Katy
”moo codes”
Yes its working i applied it thorough edit html on blogger ...
ReplyDeleteVertical Jump Bible
good article
ReplyDeletehello there is solution i have got just visit this link
ReplyDeletehttp://www.simplebits.com/cgi-bin/simplecode.pl?mode=process
you can view the sample at this blog http://vanther-x.blogspot.com
♥
ReplyDeletegot some technical articles covered here , please let me know your feedback
ReplyDeletehttp://technicalwizardry.blogspot.in/
Thanks! It's working to my blog check here How To Remove Your Author Profile On Your Blogspot Homepage
ReplyDelete