Saturday, July 7, 2007

Code Snippet plugin for Windows Live Writer

One of WLW features of interest to the geek in me is its support for plugins via its SDK. As you may already know, a plugin allows developers to extend an application with additional features.

A good part of my posts contain source code snippets to illustrate and/or compliment the content. Instead of using plain text to represent the code snippets I have been using CSS-based syntax highlighting thanks to the online code formatter written by Jean-Claude Manoli.

When I started using WLW I looked for plugins to see what useful features others have created. The Writer Windows Live Gallery has a growing list of plugins. I had found the Insert Formatted Clipboard, Paste from Visual Studio and Insert Code for Windows Live Writer, all for formatting and/or applying syntax highlighting to sample source code. But while using them I found that there were things I wanted to do that these plugins did not offer. So, I wrote the Code Snippet plugin based on the syntax-highlighting code that Jean-Claude made public.

The following image shows the main Code Snippet window that you can use to interactively review the sample code before inserting into your post.

Code Snippet dialog - Full Mode (click for full image)

Some of the features in the Code Snippet plugin are:

Run Silent - use latest settings to automatically process current clipboard contents for quick pasting without displaying the Code Snippet dialog. Press and hold the Ctrl key while activating the plugin to return to previous mode (Full or Compact).
Rich Text Editor - lets you perform final changes to the source code before pasting it into your blog post. I work with a lot of source-controlled code that I don't want to necessarily touch in that environment prior to posting. So, I wanted to have the ability to increase/decrease indents or make changes to namespaces or class names without pasting to other text editors as an intermediary step.
Expandable/Splitable Code Panes - able to view the code to process or the formatted code using the entire dialog space, in addition to viewing both contents in split mode.
Persistent Options - any changes to the options are automatically stored in an external configuration file and reloaded on next execution.
View HTML - you can view the HTML markup before inserting the code snippet.

Update (02/27/07): New features in version 1.0.1.

Compact Mode - in addition to the Full Mode, you can now also work with a compact version of the dialog that allows you to quickly select the formatting options without a preview. Switching between Full and Compact Modes is quick and painless by pressing the F12 key. The following figure shows the Compact Mode dialog for the plugin.

Code Snippet dialog - Compact Mode

Window Placement Persistence - in addition to automatically storing formatting and other options, now the window location, size, and other characteristics are also remembered.
Copy CSS Style to Clipboard - to make it easier to extract the stylesheet for inclusion in your blog's template, you can now easily copy the contents to the clipboard.

Update (03/26/07): New features in version 1.0.2.

Support for CSS snippets - Added support for syntax highlighting Cascading Style Sheets (CSS) snippets.
Embedded Styles Now Inline - Changed implementation used for embedding styles from using the class attribute to using the style attribute. The former assumed embedding the stylesheet classes as part of the generated HTML for the code snippet. The latter uses inline definitions, which proves to be friendlier to RSS feeds and e-mail delivery where the embedded CSS is not recognized.

Plus more features that should be evident once you start playing with it.

Download Code Snippet plugin for Windows Live Writer Setup

No comments: