Friday, July 16, 2010

How to post source code/syntax in Blog?

If you want to post the source code or highlight the syntax in Blogger, you can follow the below steps.
1. Login to Blogger and Go to design view
2. Edit HTML
3. Copy the CSS from Syntax Highlight CSS and paste it above the end of css section(i.e before ]]-->) in blogger template.
4.Download the code from Syntax Highlighter Support
and paste the code at the bottom after the comment, end outer-wrapper and above the end of body tag.
5. Save it and you are ready to use the syntax highlighter
Now you can post the code snippets by using “pre” or “textarea” tag as below.
In the pre tag just use, class="language" name="code". Language is the type of code we are going to put. For ex, ruby, java, xml, html etc..

Given below is the sample for ruby code.

def show_with_map
@incident = Incident.find(params[:id])
respond_to do format
render :text=>@incident.to_xml (:only=>[:latitude, :longitude, :title, :description], :root=>"data")


Thanks for the original source from Heisencoder Blog.

No comments:

Post a Comment