BritishDeveloper
BritishDeveloper

Reputation: 13369

How to style a code block to make all the colours look pretty like my IDE and here in stackoverflow?

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

Answers (8)

BritishDeveloper
BritishDeveloper

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

fortran
fortran

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

Luca Filosofi
Luca Filosofi

Reputation: 31173

UPDATED:

link tutorial

Upvotes: 1

SeanJA
SeanJA

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

Simeon Pilgrim
Simeon Pilgrim

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

Zack Marrapese
Zack Marrapese

Reputation: 12090

Try this syntax highlighter. If you are using a particular CMS, there are probably modules already created for this.

Upvotes: 1

brabster
brabster

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

Dave Swersky
Dave Swersky

Reputation: 34810

Google "syntax highlighter". There are a bunch of libraries out there, many use javascript.

Upvotes: 1

Related Questions