Posting Source Code with Microsoft Live Writer and WordPress


Today I searched for a solution to post source code using Microsoft Live Writer to my blog hosted on WordPress.com.

WordPress itself has an integrated Syntax Highlighter supporting most popular languages. Details of how to use it can be found here.

But how do you use the WordPress Syntax Highlighter when using Microsoft’s Live Writer (which I really find a good tool for offline writing) for posting? There are syntax highlighting Plug-ins available for Live Writer, but they are all not compatible with the WordPress way of syntax highlighting. After doing some Google searches, I’ve found a special Live Writer Plug-in supporting WordPress written by Rich Hewlett. It can be downloaded here.

After that inserting nicely formatted source code is just a matter of a few mouse clicks:

 public static BusinessEvent buildEvent(String input)
        throws Exception
    {
        QName eventName =
            new QName ("http://schemas.oracle.com/events/edl/HelloWorldEvents",
                       "InitiateHelloWorldEvent");
        BusinessEventBuilder beb = BusinessEventBuilder.newInstance();
            // set the event name (that matches the QName of the EDL)
            beb.setEventName(eventName);
            // payload element as dom
            beb.setBody(createElementFromInput(input));
            UUID uuid = UUID.randomUUID();
            beb.setProperty(BusinessEvent.EVENT_ID, uuid);
            // the conversation id can help to find the composite instance later via conv id.
            beb.setProperty(BusinessEvent.PROPERTY_CONVERSATION_ID, uuid);
        return beb.createEvent();
    }

Thanks Rich for developing this really usable Live Writer Plug-in for WordPress!