Looking for another way to add content to this site without using a browser and have a few more features, I came across Windows Live Writer. I quickly realized I needed a way of adding Code tags (with Syntax Highlighting), and being a programmer, went about looking at my options. I figured a Plugin would be the best way of doing this.
ContentSource
There are numerous sources on how to do this by deriving your plugin from ContentSource (WindowsLive.Writer.Api.dll) except I quickly realized a problem – the HTML being displayed in WLW and being published are the same for these sources. This is a problem – the preview for the code tag won’t have any Syntax Highlighting as you locally don’t have the library.
Enter SmartContentSource
According to the official Documentation:
Enable the insertion of HTML content with “smart” editing capabilities into a post. These capabilities include atomic selection, two-way editing by using the Sidebar, the ability to be resized, and the ability to have distinct HTML representations for editing and publishing contexts.
This is exactly what I was after – distinct representations. However, web searches revealed no references. As I have written in my plugin’s page Live Syntax, I turned to reverse engineering/decompiling the included assemblies. Using the WindowsLiveLocal.WriterPlugin.MapContentSource plugin as a guide, I looked into solving my biggest problem – having separate editing and publishing HTML.
WindowsLive.Writer.Api.SmartContentSource
SmartContentSource is an abstract class with the following definition (according to Reflector).
public abstract class SmartContentSource : WriterPlugin
{
// Methods
protected SmartContentSource();
public virtual DialogResult CreateContent(IWin32Window dialogOwner, ISmartContent newContent);
public virtual DialogResult CreateContentFromLiveClipboard(IWin32Window dialogOwner, XmlDocument lcDocument, ISmartContent newContent);
public virtual void CreateContentFromUrl(string url, ref string title, ISmartContent newContent);
public abstract SmartContentEditor CreateEditor(ISmartContentEditorSite editorSite);
public virtual string GenerateEditorHtml(ISmartContent content, IPublishingContext publishingContext);
public abstract string GeneratePublishHtml(ISmartContent content, IPublishingContext publishingContext);
public virtual void OnResizeComplete(ISmartContent content, Size newSize);
public virtual void OnResizeStart(ISmartContent content, ResizeOptions options);
public virtual void OnResizing(ISmartContent content, Size newSize);
// Properties
public virtual ResizeCapabilities ResizeCapabilities { get; }
}
As we can see, there exists two seperate methods for generating HTML, exactly what we are looking for. There are also Resize functions to check out (and overriding the related property), and CreateContent which occurs when the button is clicked on the WLW UI. This plugin creates a DialogWindow to get its content.
Are we done?
Not quite. At this point, I wanted to have the Plugin render an Image of the highlighted syntax, as it would place a bit nicer with WLW and how it handles SmartContentSources. Now the next step is to render an image of the highlighted syntax in action, and find a way of writing it just to the Editor HTML. All this in part 2.