Monday 16 May 2011

Syntax highlighting in your blog for C++(can be extended to other programming languages as well)

Its just been a few days since I started blogging and one major road block i faced was being able to provide syntax highlighting for various code snippets in my blog. The monochrome text often looks boring and and also so unwelcoming to the readers. So I decide to do some goggling on syntax highlighting for blogs. As usual Google didn't disappoint me when it comes to giving results, what disappointed me is none of them were apt and feasible for me.Just finding no luck i just paused my (RE)Search :P on this topic and continued to blog it the way the blogger allows me to.

It Struck to me that gvim supports syntax highlighting and also allows us to export the code in format of html. At last i found the way to achieve it. if you have read through all the above crap here is a brief tutorial.

I assume u can Google and download gvim.

Step1: Write your code or paste your code onto the editor window.

Step2: Choose a color scheme(Step2 and Step3 are interchangeable)

Step3: Turn on the Syntax highlighting for this file.

Step4:You can now see the code with syntax highlighting

Step5: Generate an HTML file for the code file.

Step6:You now have the html with styling for the syntax highlighted code file of yours.


Step7:Exclude the html and the body tags, now copy the CSS styles and the contents of the pre tag to the blog's Editor.Go to Edit HTML option and paste the copied styling and tags in the necessary location of the div tag. You are good to go with your syntax highlighted posts. 

No comments:

Post a Comment