Hi Friends,

If you are a developer & want to share your code over the blog with proper highlighting & syntax, then Blogger/Wordpress doesn't have the immediate solution out here!

A quick workaround for Blogger can be to embed your source between:
<blockquote></blockquote>
tags in order to prevent them from getting parsed.
E.g.


Site

But for the formatting & highlighting used to quote above
example, an excellent open source tool called SyntaxHighlighter is available.

This is ready to use out of box 100% Javascript based SyntaxHighlighter with extensive features & multiple other options.

SyntaxHighlighter can be either downloaded & used on your own webserver or if you have a blog on Blogger, this can be directly used as well.

To downloaded SyntaxHighlighter for your own personal Webserver/Hosted Site: http://alexgorbatchev.com/wiki/SyntaxHighlighter:Download
Configuration Steps: http://alexgorbatchev.com/wiki/SyntaxHighlighter:Configuration
Brush Aliases:http://alexgorbatchev.com/wiki/SyntaxHighlighter:Brushes

In order to install & use it on Blogger, follow the below simple steps:
1) Go to your Template Layout->Download your template as a backup first
2)Now click Edit HTML for Layout & then paste the below code in your Template before your </head> tag ends. Note this is pointing to the Latest released version v2.1.364; older versions can be found at: http://alexgorbatchev.com/pub/sh/
 


















3)Save the template & open you blog in IE & Firefox to test if any javascript errors are reported as this might conflict with various other embedded scripts in your template.

This completes the direct embedding of SyntaxHighlighter in your Blog. Now lets proceed how to use it in your posts:

Usage:
For SyntaxHighlighter 2.0 & above:
Any code you want to be placed & displayed using SyntaxHighlighter must be enclosed in:
 



Note that we have option of using different brushes for highlighting different type of codes..e.g. HTML/ASP/C++ etc
In order to choose the appropriate brush, following are the various brush aliases supporting the corresponding code highlighting:
actionscript3
bash, shell
c-sharp, csharp
cpp, c
css    
delphi, pas, pascal
diff, patch
groovy
js, jscript, javascript
java
jfx, javafx
perl, pl
php
plain, text
ps, powershell
py, python
rails, ror, ruby
scala
sql
vb, vbnet
xml, xhtml, xslt, html, xhtml

Above aliases can be used at: class="brush: alias" while embedding your code in the Blog.

Another easy way supported by SyntaxHighlighter is to enclose the code within:


#########YOUR CODE########
The only catch involved out here is, you have to use encoded HTML while embedding within <pre>tags.Your code can be converted to HTML Encoded using following easy to use Tool:
http://www.string-functions.com/htmlencode.aspx

Just copy paste your code & generate the encoded HTML Code. Paste the encoded HTML within <pre>tags for correct rendering. Failure to do so might render wrong code, especially < & > brackets.

Some examples of codes in my Blog:
http://geektalkin.blogspot.com/2009/07/historical-audit-trail-information.html

http://geektalkin.blogspot.com/2009/11/batch-program-to-rename-file-with-date.html

Keep Blogging!
Blogger, Embed Code, Code, Syntax, Syntax Highlight, Syntaxhighlighter, Javascript, Blog Tricks, Blogs, Java, SQL, ASP, HTML, HTM, C#, XML, XSL, JS, CSS, PHP, PL, CGI, embed code blog,embed blogger blog, embed youtube blogger, swf embed code, you tube embed code, embed src code, embed wordpress blog, embed video blogger, myspace embed code,embed into, html code,rss feeds,blogger templates, blogger,syntax highlighting,script error,script,etc

0 comments:

Luncurkan toko Anda hanya dalam 4 detik dengan 
 
Top