wordpress – Ticklish Techs https://www.ticklishtechs.net a mostly .NET but also some other cool techs blog Thu, 13 Aug 2020 18:46:56 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.11 Windows Live Writer Plugin for <code> in WordPress https://www.ticklishtechs.net/2008/02/21/windows-live-writer-plugin-for-code-in-wordpress/ Thu, 21 Feb 2008 11:55:17 +0000 http://www.ticklishtechs.net/2008/02/21/windows-live-writer-plugin-for-code-in-wordpress/ 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.

]]>