Live Syntax

Live Syntax is a plugin for Windows Live Writer that allows for easy insertion of code to be highlighted by a syntax highlighter plugin on a blog, like SyntaxHighlighter Evolved for WordPress.

Details

Live Syntax shows a preview of how the code will look when it is live on your blog, and supports all the languages of the underlying JavaScript Syntax Highlighter by Alex Gorbatchev.

Notes

During the development of LiveSyntax, I came across a show-stopping shortcoming in how WLW parses the HTML. It “pretties” the HTML and removes the line breaks from the source where it thinks it doesn’t need them. If the code is wrapped in just short-code tags (square brackets), it will be reduced to one line, removing all of the benefit of posting code. The only solution is to wrap it in a <Pre></Pre>  and set the padding, margin, and line height to 0px. This was a pretty disappointing work around. There is an API to examine the final HTML as read only, so using a plugin helper won’t work either.

Developement

The MSDN documentation for the Windows Live Writer Plugin API is poorly written, with limited details and no examples. Therefore, development of the plugin occurred mostly by reverse engineering, made easy by the various assembly exploring tools that exist for .Net like ILSpy.

The assembly that must be referenced by Visual Studio is C:\Program Files (x86)\Windows Live\Writer\WindowsLive.Writer.Api.dll. All plugins must have the WriterPluginAttribute, and searching through the other assemblies in the Writer folder revealed WindowsLiveLocal.WriterPlugin.MapContentSource. By using the converted IL to C# for this assembly, I was able to learn enough from the API to write Live Syntax (like how to link temporary images just for previewing).

Download

Live Syntax is released as open source, to give you documentation on the API from a practical standpoint.

Live Syntax Assembly
Live Syntax Source

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>