Reputation: 13369
When putting code samples in my blog I would like the code to have all the appropriate colours. How can I do that?
Basically if I write:
foreach (ListItem item in items)
{
item.Text = "something";
}
I want it to appear in the correct colours like it does in my Visual Studio or here at stackoverflow.
I'm bored of styling the colours of each key word manually. Is there a pre-existing javascript library I can use?
EDIT: I'm using blogger as my blogging platform if that helps
Upvotes: 1
Views: 520
Reputation: 13369
Really I'd like to have jballs comment as the answer... but I can't. He was right though - SyntaxHighlighter seems to be the easiest to get/use and there is a lot of support for it too.
I implemented it really quickly. Tested it and explained my steps here: Colouring code with Syntax Highlighter
Upvotes: 0
Reputation: 76077
You can also use vim's export as html, and then copy&paste in blogger. No the best solution, but probably the simplest.
Upvotes: 0
Reputation: 10374
You can also use a place that hosts the code (like http://gist.github.com , http://snipplr.com/ , and various other 'pastebin' services) and then just use the embed script that they provide.
Upvotes: 2
Reputation: 26043
I used Windows Live Writer for a while, and there is a plugin to paste from Visual Studio, that does the colour coding for you. I then coded that content into my Blogger/Wordpress post.
Now I use a java based plug-in for Wordpress SyntaxHighlighter Evolved, which provides line wrapping.
Upvotes: 1
Reputation: 12090
Try this syntax highlighter. If you are using a particular CMS, there are probably modules already created for this.
Upvotes: 1
Reputation: 43580
A common approach is to use a JavaScript library to style up the code samples. You can use prettify to do syntax highlighting on a webapage, the README explains exactly how to do it.
Upvotes: 2
Reputation: 34810
Google "syntax highlighter". There are a bunch of libraries out there, many use javascript.
Upvotes: 1