Windows Live Writer: Paste from Visual Studio
2006-10-06 16:42:48

Announcing: Paste from Visual Studio

Easily transfer syntax highlighted source code from Visual Studio to elegant HTML in Windows Live Writer. Copy from Visual Studio and insert directly to Windows Live Writer to maintain your unique syntax highlighting settings

The plugin is available for download from the Windows Live Gallery.

I've blogged before about getting code samples from Visual Studio into nicely formatted HTML. Recently I've been using Windows Live Writer to author my entries but still using my old method to cut and paste formatted HTML. Yesterday it dawned on me that it would be entirely trivial to build a plugin to make this entire issue basically a no-op. And it was.

So now I can CTRL-C in Visual Studio, click a button in Windows Live Writer and bam, pretty code like this:

using WindowsLive.Writer.Api;
using System.Windows.Forms;

[WriterPlugin("{5dc7327d-6a8e-4609-aec0-719cb5db79e7}", "VSPaste")]
[InsertableContentSource("Paste from Visual Studio")]
public class VSPaste : ContentSource
    public override DialogResult CreateContent(IWin32Window dialogOwner, ref string newContent)
        if (Clipboard.ContainsData(DataFormats.Rtf))
            newContent = HTMLRootProcessor.FromRTF((string)Clipboard.GetData(DataFormats.Rtf));
            return DialogResult.OK;

        return DialogResult.Cancel;

In fact that's all the code for the plugin, everything else is unchanged (well except bug fixes) from my previous RTF to HTML efforts.