Windows Live Writer Plugin for <code> in WordPress
Tags: dotnet, example, wlw, wordpressNo Comments »
I wrote the last posts (and also this one) with Windows Live Writer (aka. WLW). It is a very powerful offline client for writing posts to many different blog systems. Although it is a Microsoft software you can post to WordPress blogs.
But I was missing one function I’m using very often when I write posts on programming. There is no way in the WYSIWYG editor of WLW to format Text like this
. In WordPress you can use the <code></code>
tags for code-like formatting. But in WLW I had to switch to the HTML Code view to add these tags.
Since there is a good API to add features to WLW I tried to write my first Windows Live Write Plugin:
[WriterPlugin("{52D29C0E-49E6-4353-B58C-458F86CA1E2B}", "Inline Code Plugin")] [InsertableContentSource("Inline Code")] public class WlwInlineCodePlugin : ContentSource { public override DialogResult CreateContent (IWin32Window dialogOwner, ref string newContent) { InputBox box = new InputBox("Insert inline code",
"Insert the following in a <code> block:",""); DialogResult result = box.ShowDialog(dialogOwner); if (result == DialogResult.OK) newContent = "<code>" + box.Input + "</code>"; return result; } }
That’s really all the code (besides the InputBox
. Just add the two attributes to a class and override the CreateContent()
method. The code in this method is straight forward: Show some dialog, create the new HTML content and return the DialogResult
.
After compiling you have to put the dll into the Plugin
directory of your WLW installation and you will see a new entry in the Insert menu and on the sidebar. This entry is called "Insert Inline Code…" (ah, the text from the attribute goes there). When you click it a small dialog asks for the text and if you exit the dialog with the OK button this text is added to your document inside of <Code>
tags.
In the zip file you will find the source code and the compiled dll.
Recent Comments