Insert Code for Windows Live Writer

Several pople have asked me recently about the nice code syntax highlighting in my blog. For example:

public string Test()
{
  //Look at the pretty colors
  return "Yay!";
}

A long time ago, I wrote about using http://www.manoli.net/csharpformat/ for converting code to HTML.

But these days, I use Omar Shahine’s Insert Code for Windows Live Writer plugin for, you guessed it, Windows Live Writer. This plugin just happens to use the Manoli code to perform syntax highlighting.

Plugin Screenshot

I recommend downloading and referencing the CSS stylesheet from the Manoli site and making sure to uncheck the Embed StyleSheet option in the plugin.

The dropshadow around the code is some CSS I found on the net.

What others have said

Requesting Gravatar... Ryan Apr 27, 2007 2:34 PM
# re: Insert Code for Windows Live Writer
You realize of course, that if you do not embed the CSS inline that it does not show in RSS aggregators, right? While the few users that read the actual HTML website will see pretty things, people that use RSS readers will not see anything.
Requesting Gravatar... Haacked Apr 27, 2007 3:07 PM
# re: Insert Code for Windows Live Writer
True. It's the price I pay for seeking out XHTML compliance. ;)
Requesting Gravatar... Jeff Atwood Apr 27, 2007 3:38 PM
# re: Insert Code for Windows Live Writer
And yet the code is completely colorless in my RSS reader.. that's why I've devolved to old-school embedded FONT tags, which may not be pretty, but they work in every RSS reader on the planet.
Requesting Gravatar... Filini Apr 27, 2007 5:46 PM
# re: Insert Code for Windows Live Writer
[...] old-school embedded FONT tags [...]
But Jeff... that is sooooooooo FrontPage! :P

In a distant future, browsers will give a real purpose to the tag, using the (deprecated) language attribute... so that, instead of using <pre class="csharpcode"> with many subclasses, you will just write and all the keywords will be handled by the browser...

oh well... one can dream :)
Requesting Gravatar... Filini Apr 27, 2007 5:57 PM
# re: Insert Code for Windows Live Writer
Woops! A piece of code was eaten by some computer imp... my last sentence was:

[...] you will just write <code language="csharp" and all the keywords will be handled by the browser...
Requesting Gravatar... Rick Strahl Apr 28, 2007 1:21 PM
# re: Insert Code for Windows Live Writer
FWIW, there are a couple of other plug-ins for Live Writer that are maybe easier. Using one of the Visual Studio plug-ins (or Jeff's Macro) to copy VS.NET code to HTML you can use these plug-ins to post HTML code.

The advantage of this is that it will work with RTF code that Visual Studio understands and with some of the plug-ins you get a bunch of formatting options.

In fact - I've been meaning to create a plug-in for Paste from RTF (maybe somebody's done that by now) which would be easier yet since you could just copy directly from VS (or any RTF output for that matter).
Requesting Gravatar... Jeff Atwood Apr 29, 2007 12:01 AM
# re: Insert Code for Windows Live Writer
> you will just write and all the keywords will be handled by the browser...

You can do that now with JavaScript.

http://www.dreamprojections.com/SyntaxHighlighter/

I've tried both ways, but I prefer embedded HTML using the old-school FONT tag which works literally everywhere.
Requesting Gravatar... Filini Apr 29, 2007 9:40 AM
# re: Insert Code for Windows Live Writer
Yes, right now the FONT tag is the best solution for all the different browsers/clients.
My dream was to need NO solution at all, since HTML provides a nice CODE tag :-)
Requesting Gravatar... Mads Kristensen Apr 30, 2007 2:03 AM
# re: Insert Code for Windows Live Writer
Font tags are very ugly I think. The best way would be to style the different span tags directly in the HTML. That also works in RSS readers
Requesting Gravatar... Simone May 10, 2007 9:44 PM
# re: Insert Code for Windows Live Writer
If you use styles directly inside the HTML the size of the post will become huge since every different keyword can have different colors :)
Requesting Gravatar... Eamon Nerbonne May 14, 2007 8:25 AM
# re: Insert Code for Windows Live Writer
Well if the choice is a somewhat larger post or color... well... give me the color already! Even if it's 4 times the size, that's definitely my preference.
Requesting Gravatar... Steve Dunn May 16, 2007 8:15 AM
# re: Insert Code for Windows Live Writer
I did a plug-in for this a while back. It also supports quick pasting of code from the clipboard. Supports many languages too. Check it out at on my tools page at http://tools.dunnhq.com. The direct link is http://stevedunns.googlepages.com/codeformatterforwindowslivewriter

Cheers,

Steve Dunn
Requesting Gravatar... Sneal's Blog Jul 28, 2007 9:24 PM
# Code Formatting, Why do you Hate me?!

What do you have to say?

(will show your gravatar)
Please add 8 and 6 and type the answer here: