Skip to content
October 8, 2006 / jphoward

CopySourceAsHtml (CSAH)

CopySourceAsHtml is very helpful for ‘pretty printing’ source code in web pages, without requiring any special software on your web server.

CopySourceAsHtml is an add-in for Microsoft Visual Studio 2005 that allows you to copy source code, syntax highlighting, and line numbers as HTML. CSAH uses Visual Studio’s syntax highlighting and font and color settings automatically. If Visual Studio can highlight it, CSAH can copy it, and your source should look the same in your browser as it does in your editor.

This is handy with Windows Live Writer, when using the PasteSourceAsHtml plugin. It turns out that Writer plugins are really easy to create – here’s the entire source code for PasteSourceAsHtml (copied/pasted to this post using these tools):

[WriterPlugin(“6317F6F1-D284-45D3-9634-99EEAD02D16C”,

    “Paste as Html”, ImagePath = “Images.Paste.png”,

    PublisherUrl = “http://blogs.sqlxml.org/bryantlikes”,

    Description = “Paste html from your clipboard into the post”),

    InsertableContentSourceAttribute(“Clipboard Html”)]

public class Plugin : ContentSource {

    public override DialogResult CreateContent(

        IWin32Window dialogOwner, ref string newContent) {

        DialogResult result = DialogResult.OK;

        if (Clipboard.ContainsText()) newContent = Clipboard.GetText();

        else {

            result = MessageBox.Show(dialogOwner, “Copy your HTML to the clipboard.”,

                “Paste as Html”, MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK && Clipboard.ContainsText())

                newContent = Clipboard.GetText();

        }

        return result;

    }

}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: